Search code examples
linuxpostgresqlcron

How can l start postgresql database using linux crontab?


su - postgres
pg_ctl start

postgresql database is starting in this way.

but when I use linux crontab to start postgresql,it has failed.

su - postgres
crontab -e

*/1 * * * * nohup /home/postgres/pgsql/bin/pg_ctl start &

postgresql is not starting.

I want to know why.

Thank you!


Solution

  • You need to define which PostgreSQL instance to start.

    Try to add -D "PGDATA".

    For example:

    nohup /home/postgres/pgsql/bin/pg_ctl start -D /pg/data &
    

    If your Linux distribution is using systemd and a systemd unit has been defined for PostgreSQL you can also use systemctl to start PostgreSQL