How to Solve Error Message pg_ctl: no operation specified when starting PostgreSQL database server using pg_ctl

Posted on

Introduction

The following is actually has the same content with the previous article. The main focus is to be able to start PostgreSQL database server. But this article is using different command to start the PostgreSQL database server. It is using ‘pg_ctl’ instead of ‘postgres’. The complete execution of the command displaying the error message appear as follows :

[pgsql@10 bin]$ /opt/postgresql-12.0/app/bin/pg_ctl
pg_ctl: no operation specified
Try "pg_ctl --help" for more information.
[pgsql@10 bin]$ /opt/postgresql-12.0/app/bin/pg_ctl -D /opt/postgresql-12.0/data/
pg_ctl: no operation specified
Try "pg_ctl --help" for more information
[pgsql@10 bin]$

Solution

The solution is simple, just add the operation as an additional parameter after the command. So, the command exist as follows :

/app_folder_location_of_postgresql_database_server/bin/pg_ctl operation_parameter

The full execution of the command exist as follows :

[pgsql@10 bin]$ /opt/postgresql-12.0/app/bin/pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
[pgsql@10 bin]$

Well, off course it is not enough only for specifying the operation parameter. The command ‘pg_ctl’ also need another parameter. It is a parameter for specifying the location of the data directory of the PostgreSQL database server. Read the article exist with the title of ‘How to Solve Error Message no database directory specified and environment variable PGDATA unset when starting PostgreSQL Database Server in Linux’ in this link. Another one is also exist in the article with the title of ‘How to Solve Error Message postgres does not know where to find the server configuration file when Starting PostgreSQL Database Server in Linux’ in this link. So, the full command execution exist as follows :

[pgsql@10 bin]$ /opt/postgresql-12.0/app/bin/pg_ctl -D /opt/postgresql-12.0/data start
waiting for server to start....2021-06-17 03:27:26.472 EDT [87496] LOG: starting PostgreSQL 12.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5), 64-bit
2021-06-17 03:27:26.472 EDT [87496] LOG: listening on IPv6 address "::1", port 5432
2021-06-17 03:27:26.472 EDT [87496] LOG: listening on IPv4 address "127.0.0.1", port 5432
2021-06-17 03:27:26.477 EDT [87496] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-06-17 03:27:26.496 EDT [87497] LOG: database system was shut down at 2021-06-17 03:01:57 EDT
2021-06-17 03:27:26.500 EDT [87496] LOG: database system is ready to accept connections
done
server started
[pgsql@10 bin]$ psql -Upgsql postgres
psql (12.0)
Type "help" for help.
postgres=# \q
[pgsql@10 bin]$ ps -ef | grep postgres
pgsql      87496       1  0 03:27 ?        00:00:00 /opt/postgresql-12.0/app/bin/postgres -D /opt/postgresql-12.0/data
pgsql      87498   87496  0 03:27 ?        00:00:00 postgres: checkpointer
pgsql      87499   87496  0 03:27 ?        00:00:00 postgres: background writer
pgsql      87500   87496  0 03:27 ?        00:00:00 postgres: walwriter
pgsql      87501   87496  0 03:27 ?        00:00:00 postgres: autovacuum launcher
pgsql      87502   87496  0 03:27 ?        00:00:00 postgres: stats collector
pgsql      87503   87496  0 03:27 ?        00:00:00 postgres: logical replication launcher
pgsql      87926   85903  0 05:09 pts/1    00:00:00 grep --color=auto postgres
[pgsql@10 bin]$

The advantage of using ‘pg_ctl’ instead of ‘postgres’ is available at the above output command. After finishing to execute the command, the command line is not being occupied continuously by the process. So, the command for checking the process can be directly executed in the same command line interface.

One thought on “How to Solve Error Message pg_ctl: no operation specified when starting PostgreSQL database server using pg_ctl

Leave a Reply