Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a psql command line?

I'm trying to create a postgresql user and password. This tutorial supplies the command to create a user, but I can't find anywhere how to actually start the psql command line, where I would then run the CREATE USER command.

How can I start a psql command line? I'm using Ubuntu 14.04.

I tried just running psql, but I get back

psql: FATAL:  role "user" does not exist

But I can't create a user without logging into the command line...

like image 915
Jeff Caros Avatar asked Oct 21 '15 00:10

Jeff Caros


People also ask

How do I start PostgreSQL from terminal?

Getting a PostgreSQL command prompt You can get a command shell in Windows by running cmd.exe. The CSEP544 shell launcher script will also open a shell for you. Type psql -U postgres at the prompt, and hit Enter. Here, postgres represents the username of the database superuser.

What is psql command line?

psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, input can be from a file or from command line arguments.

How do I start postgres client?

Click on the "Add a connection to a server" button (top left). In the new dialog, enter the address 127.0. 0.1, a description of the server, the default database ("mydb" in the example above), your username ("postgres") and your password.

How do I run a PostgreSQL script?

To execute a . sql file on your PostgreSQL database from the command line using psql , use the -f argument to specify the file you want to run. For example, if you have a database running locally, you can run psql -h localhost -p 5432 -U postgres -f stuff.


1 Answers

psql if run by default without any arguments takes the current user name which obviously does not exist, since you just installed a postgresql.

From the other hand ubuntu's postgresql distribution comes with a default postgres user created (both in system and in postgresql databse). Which means that if you run a psql command on behalf of a postgres user then you would be able to connect:

sudo -u postgres psql
like image 157
zerkms Avatar answered Oct 26 '22 22:10

zerkms