I would like to have my PostgreSQL database start itself up. But currently need to run the following:
Terminal 1:
sudo su - posgresql
cd /usr/lib/postgresql/9.6/bin/
./postgres -D /usr/local/pgsql/data
Terminal 2:
$ sudo -u postgres psql
I would prefer to only need to run terminal 2 and am unsure why Terminal 1 isn't done automatically.
I was able to confirm that PGDATA is unset by running:
$ pg_ctl start -l logfile
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
I found some useful instructions in the postgres manual that say I should be adding /usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data
to a /etc/rc.d/rc.local
or /etc/rc.local
but neither of these dirs exist in on Ubuntu 16.04.
I feel I'm missing a simple command to set PGDATA which will start my server automatically. But I don't know what it is or what file I should store this command in.