Ubuntu – “postgres: command not found” / after regular install of postgres and configure new data directory

command linepermissionspostgresqlserver

I am setting up a POSTGRESQL on a UBUNTU 16.04 server:

I followed the explanation given here, I did:
The install:

sudo apt-get install postgresql postgresql-contrib`

The setup of postgres user and password:

sudo -u postgres psql postgres
\password [postgres password]

At that point the command postgres worked.

Then before creating any SCHEMA, I followed up some guidelines to set up a new data directory for POSTGRES under /srv/datadisk01/database, datadisk01 being a harddrive meant to store and use the database.

I changed the owner of /srv/datadisk01/database to postgres user with chmod.

I launched: /usr/lib/postgresql/9.5/bin/initdb -D /srv/datadisk01/database, which worked.

Then I ran sudo service postgresql stop. I updated the file /etc/postgresql/9.5/main/postgresql.conf,
changing

data_directory = ‘/var/lib/postgresql/9.5/main’

to

data_directory = ‘/srv/datadisk01/database’

And sudo service postgresql start.

I stopped there and switched to other topics settings not regarding POSTGRES.

Later on (and a reboot of the machine), command postgres fails and returns:

postgres: command not found

I can look how to re-configure the environment variable to make it work and I will, but I wonder if there is a reason that the command availability disappeared from the environment variable after the implementation of a custom data directory?

Best Answer

postgres execution command is psql and not postgres

postgres is the username

info from pgGettingStarted

To test your connection using psql, run the following command:

psql -U postgres -W
Related Question