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

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.

主站蜘蛛池模板: 喜德县| 青浦区| 利辛县| 莒南县| 内乡县| 永丰县| 丹江口市| 德江县| 兴义市| 遂溪县| 奎屯市| 施甸县| 永修县| 民和| 沁水县| 广元市| 白城市| 衡山县| 剑川县| 正宁县| 黄梅县| 黎城县| 桃江县| 大田县| 怀来县| 习水县| 精河县| 台前县| 周至县| 克拉玛依市| 南丰县| 福海县| 绍兴县| 梁平县| 朔州市| 大姚县| 会泽县| 醴陵市| 贵港市| 牡丹江市| 鲁山县|