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...
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With