0

I am new to technologies , please do not judge my question too strong :).

I installed in My Ubuntu 18.04 PostgreSQL 10.7. To be able to enter my DB I need to enter the following commands from my terminal. sudo -u postgres psql. Is there any shortened way where I can connect it from my Ubuntu User account. For example. if I input psql it will open database environment where I can type PostgreSQL commands.

Thank you.

1
  • psql -U postgres? Commented Apr 19, 2019 at 5:15

3 Answers 3

1

Just execute this command in your terminal :

alias psql='sudo -u postgres psql'

So the next time, you input psql and execute, you will be in database environment.

Sign up to request clarification or add additional context in comments.

Comments

0

I see two options:

1) Create alias for this command sudo -u postgres psql .

2) Go to psql and create new superuser and database for it:

CREATE ROLE username SUPERUSER;
ALTER ROLE username WITH LOGIN;
CREATE DATABASE username;

1 Comment

To create or manage tables, no superuser role is needed. A regular user is the much better choice.
0

You shouldn't be using the superuser account for your normal database work. That is as if you were using root for everything in Linux.

You need to create a regular user with the privileges to create or modify tables in your database. This can be done by granting the user all privileges on the database (which is not the same as making that user a superuser) or make that user the owner of that database.

As documented in the manual psql tries to connect to a database with the name of the current Linux user and with a database user with the name of the current Linux user. So if you want to keep things simple create a user with your regular Linux user's name and an database that is owned by that user:

create user rob password 'somepassword';
create database rob owner = rob;

Assuming your Linux user is rob, then all you need to do is:

psql

and you are connected to a database where you can create and manage tables.

Depending on how you installed Postgres, you might need to adjust pg_hba.conf to allow rob to log in directly.


Again: please do NOT use the superuser account for your normal work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.