Question

Installing PostgreSQL on GCE requires root password to run sudo -u postgresql. This prompts for a password, which I was never given.
How do I get this pass, or any way to run postgresql commands from the shell in a different way?

Was it helpful?

Solution

Your system user postgresql doesn't have a password (I state with no proof... but I think you'll find this to be true.)

Normally you should use commands like these:

# Test that YOU can use psql (as postgres) to run a query:
psql -U postgres -c 'select * from pg_catalog.pg_user;'

# Test an interactive session:
psql -U postgres my_database
my_database=# select 42 as the_answer;

# Create a new database
psql -U postgres my_database
my_database=# create database mydb;


Alternatively, it's probably possible to login like this (it usually is):

sudo su postgres

And you could probably use this to run createdb. But running psql as yourself is probably better.

OTHER TIPS

If you want to run commands against your postgresql server you should not need to use sudo, just use this syntax to enter the Postgresql Interactive Shell:

psql -U username database_name

OR

psql -U username hostname database_name

Replacing username with your postgresql usename, hostname (if not running on the same server) with the servers host name and database_name with the name of your database. For example:

psql -U postgressql customers

Normally sudo requires your user account password. So assuming that the account you are running the command from is listed in the sudoers file, the password it is prompting you for should be your own. Have you tried that, as opposed to the root or the postgresql password, which you don't appear to have (or might not even be set).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top