1. 개요


2. apt 설치 및 삭제

2.1. 설치

ubuntu 기준으로 하여, apt로 설치한다.

$ sudo apt install postgresql
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libpq5 libsensors4 postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
Suggested packages:
  lm-sensors postgresql-doc locales-all postgresql-doc-10 libjson-perl openssl-blacklist isag
The following NEW packages will be installed:
  libpq5 libsensors4 postgresql postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
0 upgraded, 9 newly installed, 0 to remove and 52 not upgraded.
Need to get 5333 kB of archives.
After this operation, 21.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] yes
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpq5 amd64 10.10-0ubuntu0.18.04.1 [108 kB]
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 libsensors4 amd64 1:3.4.0-4 [28.8 kB]
Get:3 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 postgresql-client-common all 190 [29.5 kB]
Get:4 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 postgresql-client-10 amd64 10.10-0ubuntu0.18.04.1 [935 kB]
Get:5 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 ssl-cert all 1.0.39 [17.0 kB]
Get:6 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 postgresql-common all 190 [157 kB]
Get:7 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 postgresql-10 amd64 10.10-0ubuntu0.18.04.1 [3758 kB]
Get:8 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 postgresql all 10+190 [5784 B]
Get:9 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 sysstat amd64 11.6.1-1 [295 kB]
Fetched 5333 kB in 0s (11.6 MB/s)
Preconfiguring packages ...
Selecting previously unselected package libpq5:amd64.
(Reading database ... 84333 files and directories currently installed.)
Preparing to unpack .../0-libpq5_10.10-0ubuntu0.18.04.1_amd64.deb ...
Unpacking libpq5:amd64 (10.10-0ubuntu0.18.04.1) ...
Selecting previously unselected package libsensors4:amd64.
Preparing to unpack .../1-libsensors4_1%3a3.4.0-4_amd64.deb ...
Unpacking libsensors4:amd64 (1:3.4.0-4) ...
Selecting previously unselected package postgresql-client-common.
Preparing to unpack .../2-postgresql-client-common_190_all.deb ...
Unpacking postgresql-client-common (190) ...
Selecting previously unselected package postgresql-client-10.
Preparing to unpack .../3-postgresql-client-10_10.10-0ubuntu0.18.04.1_amd64.deb ...
Unpacking postgresql-client-10 (10.10-0ubuntu0.18.04.1) ...
Selecting previously unselected package ssl-cert.
Preparing to unpack .../4-ssl-cert_1.0.39_all.deb ...
Unpacking ssl-cert (1.0.39) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack .../5-postgresql-common_190_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (190) ...
Selecting previously unselected package postgresql-10.
Preparing to unpack .../6-postgresql-10_10.10-0ubuntu0.18.04.1_amd64.deb ...
Unpacking postgresql-10 (10.10-0ubuntu0.18.04.1) ...
Selecting previously unselected package postgresql.
Preparing to unpack .../7-postgresql_10+190_all.deb ...
Unpacking postgresql (10+190) ...
Selecting previously unselected package sysstat.
Preparing to unpack .../8-sysstat_11.6.1-1_amd64.deb ...
Unpacking sysstat (11.6.1-1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Setting up ssl-cert (1.0.39) ...
Setting up libpq5:amd64 (10.10-0ubuntu0.18.04.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Setting up postgresql-client-common (190) ...
Processing triggers for systemd (237-3ubuntu10.29) ...
Setting up postgresql-common (190) ...
Adding user postgres to group ssl-cert

Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up libsensors4:amd64 (1:3.4.0-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up postgresql-client-10 (10.10-0ubuntu0.18.04.1) ...
update-alternatives: using /usr/share/postgresql/10/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up sysstat (11.6.1-1) ...

Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.
Setting up postgresql-10 (10.10-0ubuntu0.18.04.1) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/10/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start

Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
update-alternatives: using /usr/share/postgresql/10/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Setting up postgresql (10+190) ...
Processing triggers for systemd (237-3ubuntu10.29) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

최종적으로 PostgreSQL이 떠있는지 확인.

postgres 21689     1  0 03:50 ?        00:00:00 /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf
postgres 21699 21689  0 03:50 ?        00:00:00 postgres: 10/main: checkpointer process
postgres 21700 21689  0 03:50 ?        00:00:00 postgres: 10/main: writer process
postgres 21703 21689  0 03:50 ?        00:00:00 postgres: 10/main: wal writer process
postgres 21704 21689  0 03:50 ?        00:00:00 postgres: 10/main: autovacuum launcher process
postgres 21705 21689  0 03:50 ?        00:00:00 postgres: 10/main: stats collector process
postgres 21706 21689  0 03:50 ?        00:00:00 postgres: 10/main: bgworker: logical replication launcher
ubuntu   21813  2542  0 03:54 pts/0    00:00:00 grep --color=auto postgre

2.2. 삭제

$ sudo apt-get --purge remove postgresql
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  postgresql*
0 upgraded, 0 newly installed, 1 to remove and 52 not upgraded.
After this operation, 63.5 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 85147 files and directories currently installed.)
Removing postgresql (10+190) ...

3. 접속

접속은 psql 커맨드를 사용할 수 있다. 또 접속에 대한 설정은 /etc/postgresql/10/main/pg_hba.conf 파일을 사용한다.


4. 기타