官术网_书友最值得收藏!

Starting the server manually

Normally, a PostgreSQL server will start automatically when the system boots up. If an automatic start is not enabled for a server, we would need to start the server manually. This may be required even for operational reasons.

Getting ready

Before we talk about how to start the database server, first we need to understand the difference between server and service. The term server refers to the database server and its processes, whereas the term service essentially indicates the operating system wrapper through which the server gets called.

How to do it...

On a majority of platforms, that is, Linux and Unix distributions, we can start the server using the pg_ctl command-line utility as shown here:

pg_ctl -D <location of data directory> start

Consider the following example:

pg_ctl -D /var/lib/pgsql/9.6/data start

The -D switch of the pg_ctl command indicates the data directory of the PostgreSQL server. In the preceding command, the data directory is defined at the location /var/lib/pgsql/9.6/data.

On Linux and Unix platforms such as Red Hat, the service can be started as mentioned here:

service <postgresql-version> start

For instance, to start the PostgreSQL server version 9.6 as a service, we can use the following command:

service postgresql-9.6 start

How it works...

Using the start mode of the pg_ctl command, the PostgreSQL server is started in the background and its background processes are initiated.

You can use the following command to check whether the PostgreSQL server background processes have started:

ps aux | grep "postgres" | grep -v "grep" postgres 1289 0.0 0.3 51676 7900 ? S 11:31 0:01 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf postgres 1303 0.0 0.0 21828 1148 ? Ss 11:31 0:00 postgres: logger process postgres 1305 0.0 0.0 51676 1568 ? Ss 11:31 0:02 postgres: writer process postgres 1306 0.0 0.0 51676 1324 ? Ss 11:31 0:02 postgres: wal writer process postgres 1307 0.0 0.1 52228 2452 ? Ss 11:31 0:00 postgres: autovacuum launcher process postgres 1308 0.0 0.0 22016 1432 ? Ss 11:31 0:00 postgres: stats collector process

When we execute the pg_ctl command, it internally performs various validations such as checking that the data directory that we mentioned is equal to the data_directory setting in postgresql.conf. If the data_directory parameter points to some other directory location, then PostgreSQL will instantiate to that directory location. After the validations have been completed, the pg_ctl binary internally invokes another process called postgres, which is the main process for the PostgreSQL cluster.

主站蜘蛛池模板: 玉屏| 湘潭市| 天气| 浮梁县| 紫金县| 上蔡县| 东平县| 泰宁县| 右玉县| 大连市| 阿巴嘎旗| 固阳县| 铁力市| 安福县| 栖霞市| 土默特右旗| 恩平市| 龙海市| 神池县| 海南省| 常山县| 清涧县| 星子县| 江城| 韶关市| 伊通| 交口县| 正安县| 中西区| 内黄县| 白河县| 涿鹿县| 黄山市| 洛扎县| 交口县| 龙南县| 丹凤县| 屏南县| 大化| 潜江市| 莱阳市|