"postgres: command not found" / after regular install of postgres and configure new data directory

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?

2

4 Answers

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

You can also try that

psql -U user_name -h 127.0.0.1 database_name

In case someone is looking starting the server, this is the commandsudo -u postgres /etc/init.d/postgresql start

you can use this command to initialize, start, and restart the database server

  • sudo service postgresql initdb
  • sudo service postgresql start
  • sudo service postgresql restart

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like