PostgreSQL database installation and deployment

A, postgresql database deployment

  1. Go to the directory postgresql installation package (here I deployed version 10.5)

[root@web1 ~]# cd /package/
[root@web1 package]# ls
apache-tomcat-8.5.39.tar.gz  jdk-8u131-linux-x64.tar.gz  postgresql-10.5.tar.gz  redis-3.2.0.tar.gz
[root@web1 package]#

  2, the packet decompressor

[root@web1 package]# tar xf postgresql-10.5.tar.gz
[root@web1 package]# ls
apache-tomcat-8.5.39.tar.gz  jdk-8u131-linux-x64.tar.gz  postgresql-10.5  postgresql-10.5.tar.gz  redis-3.2.0.tar.gz
[root@web1 package]#

  3, generated after files are compiled into the unpacked directory

[root@web1 postgresql-10.5]# ./configure --prefix=/usr/local/pgsql-10.5
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB

  4, suggesting that the following information is missing package file

checking for library containing readline... no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

  5, the corresponding installation package file

[root@web1 postgresql-10.5]#yum install ncurses* readline* zlib* -y
######################################
[root@web1 postgresql-10.5]# rpm -aq ncurses* readline* zlib*
readline-devel-6.2-10.el7.x86_64
zlib-static-1.2.7-18.el7.x86_64
ncurses-libs-5.9-14.20130511.el7_4.x86_64
ncurses-devel-5.9-14.20130511.el7_4.x86_64
readline-static-6.2-10.el7.x86_64
zlib-devel-1.2.7-18.el7.x86_64
readline-6.2-10.el7.x86_64
ncurses-base-5.9-14.20130511.el7_4.noarch
ncurses-5.9-14.20130511.el7_4.x86_64
zlib-1.2.7-18.el7.x86_64
[root@web1 postgresql-10.5]#

  6, after the installation is complete recompilation

[root@web1 postgresql-10.5]# ./configure --prefix=/usr/local/pgsql-10.5
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc

  7, parses the file (in postgresql-10.5 directory execute: make install), and finally output the results did not prompt abnormal [error] can begin the installation

rm -f pg_regress.o && ln -s ../../../src/test/regress/pg_regress.o .
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql-10.5/lib',--enable-new-dtags  -lpgcommon -lpgport -lpthread -lz -lreadline -lrt -lcrypt -ldl
make[2]: Leaving directory `/package/postgresql-10.5/src/test/isolation'
make -C test/perl all
make[2]: Entering directory `/package/postgresql-10.5/src/test/perl'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/package/postgresql-10.5/src/test/perl'
make[1]: Leaving directory `/package/postgresql-10.5/src'
make -C config all
make[1]: Entering directory `/package/postgresql-10.5/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/package/postgresql-10.5/config'
All of PostgreSQL successfully made. Ready to install.

  8, to start the installation (in postgresql-10.5 directory execute: make install), and finally output the results did not prompt abnormal [error] would mean that the installation was successful

/bin/install -c -m 644 Makefile.global '/usr/local/pgsql-10.5/lib/pgxs/src/Makefile.global'
/bin/install -c -m 644 Makefile.port '/usr/local/pgsql-10.5/lib/pgxs/src/Makefile.port'
/bin/install -c -m 644 ./Makefile.shlib '/usr/local/pgsql-10.5/lib/pgxs/src/Makefile.shlib'
/bin/install -c -m 644 ./nls-global.mk '/usr/local/pgsql-10.5/lib/pgxs/src/nls-global.mk'
make[1]: Leaving directory `/package/postgresql-10.5/src'
make -C config install
make[1]: Entering directory `/package/postgresql-10.5/config'
/bin/mkdir -p '/usr/local/pgsql-10.5/lib/pgxs/config'
/bin/install -c -m 755 ./install-sh '/usr/local/pgsql-10.5/lib/pgxs/config/install-sh'
/bin/install -c -m 755 ./missing '/usr/local/pgsql-10.5/lib/pgxs/config/missing'
make[1]: Leaving directory `/package/postgresql-10.5/config'
PostgreSQL installation complete.

  9, after the installation is complete you can see has become pgsql-10.5 directory in the / usr / local directory

[root@web1 postgresql-10.5]# ll /usr/local/ |grep pgsql-10.5
drwxr-xr-x  6 root root  56 May 23 18:06 pgsql-10.5
[root@web1 postgresql-10.5]#

  10, create a user and set /usr/local/pgsql-10.5 directory file owner group

[root@web1 postgresql-10.5]# useradd postgres
[root@web1 postgresql-10.5]# chown -R postgres.postgres /usr/local/pgsql-10.5/
[root@web1 postgresql-10.5]# ll /usr/local/ |grep pgsql-10.5
drwxr-xr-x  6 postgres postgres  56 May 23 18:06 pgsql-10.5
[root@web1 postgresql-10.5]#

  11, flexible connection to /usr/local/pgsql-10.5 directory settings (easy to view and manage it ....)


[root@web1 postgresql-10.5]# ln -s /usr/local/pgsql-10.5/ /usr/local/pgsql
[root@web1 postgresql-10.5]# ll /usr/local/pgsql
lrwxrwxrwx 1 root root 22 May 23 18:15 /usr/local/pgsql -> /usr/local/pgsql-10.5/
[root@web1 postgresql-10.5]#

  12, into the newly created user postgres

[root@web1 postgresql-10.5]# su postgres
[postgres@web1 postgresql-10.5]$

  13, set the environment variable (note path)

[postgres@web1 ~]$ vim ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH=$PATH:/usr/local/pgsql-10.5/bin
PGDATA=/usr/local/pgsql-10.5/data
export PGDATA
export PATH

  14, currently in effect

[postgres@web1 ~]$ source ~/.bash_profile
[postgres@web1 ~]$

  15, the test

[postgres@web1 ~]$ which psql
/usr/local/pgsql-10.5/bin/psql
[postgres@web1 ~]$ psql -V
psql (PostgreSQL) 10.5

  16, initialize the database (initdb --help view intercede), specify the library file path

[postgres@web1 ~]$ initdb /usr/local/pgsql-10.5/data
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 "en_US.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.

creating directory /usr/local/pgsql-10.5/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /usr/local/pgsql-10.5/data -l logfile start

[postgres@web1 ~]$

*** In this deployment has been successful, and now need to do is modify the configuration files in, Optimization ***

  17, went to the location of the installation file, modify the configuration file pg_hba.conf

[postgres@web1 data]$ cp pg_hba.conf pg_hba.conf.`date +%F`
[postgres@web1 data]$ vim pg_hba.conf
#######################################
# TYPE  DATABASE        USER            ADDRESS                METHOD

# "local" is for Unix domain socket connections only
local  all            all                                    trust
# IPv4 local connections:
#host    all            all            127.0.0.1/32            trust
host    all            all            0.0.0.0/0              md5    #所有ip都可以通过密码连接
# IPv6 local connections:
host    all            all            ::1/128                trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local  replication    all                                    trust
host    replication    all            127.0.0.1/32            trust
######################################

  18, went to the location of the installation file, modify the configuration file postgresql.conf

[postgres@web1 data]$ cd /usr/local/pgsql/data/
[postgres@web1 data]$ cp postgresql.conf postgresql.conf.`date +%F`
[postgres@web1 data]$ vim postgresql.conf
#########################################
# - Connection Settings -

listen_addresses = '*'  #为了方便,监听所有# what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                  # (change requires restart)
#superuser_reserved_connections = 3    # (change requires restart)
#unix_socket_directories = '/tmp'      # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                # (change requires restart)
#unix_socket_permissions = 0777        # begin with 0 to use octal notation
#########################################

  19, create a log directory for storing boot log, and start the database

[postgres@web1 data]$ mkdir /usr/local/pgsql/log
[postgres@web1 data]$ pg_ctl start -l /usr/local/pgsql-10.5/log/pg_server.log
waiting for server to start.... done
server started
[postgres@web1 data]$

  20, check whether the start, you can see the log

[postgres@web1 data]$ lsof -i:5432
COMMAND    PID    USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
postgres 25479 postgres    3u  IPv4  50990      0t0  TCP *:postgres (LISTEN)
postgres 25479 postgres    4u  IPv6  50991      0t0  TCP *:postgres (LISTEN)
[postgres@web1 data]$ netstat -lnutp|grep postgres
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:5432            0.0.0.0:*              LISTEN      25479/postgres     
tcp6      0      0 :::5432                :::*                    LISTEN      25479/postgres     
[postgres@web1 data]$ ps -ef|grep postgres
root    24060  1297  0 18:17 pts/0    00:00:00 su postgres
postgres 24061 24060  0 18:17 pts/0    00:00:00 bash
postgres 25479    1  0 18:45 pts/0    00:00:00 /usr/local/pgsql-10.5/bin/postgres
postgres 25481 25479  0 18:45 ?        00:00:00 postgres: checkpointer process 
postgres 25482 25479  0 18:45 ?        00:00:00 postgres: writer process 
postgres 25483 25479  0 18:45 ?        00:00:00 postgres: wal writer process 
postgres 25484 25479  0 18:45 ?        00:00:00 postgres: autovacuum launcher process 
postgres 25485 25479  0 18:45 ?        00:00:00 postgres: stats collector process 
postgres 25486 25479  0 18:45 ?        00:00:00 postgres: bgworker: logical replication launcher 
postgres 25543 24061  0 18:46 pts/0    00:00:00 ps -ef
postgres 25544 24061  0 18:46 pts/0    00:00:00 grep --color=auto postgres
[postgres@web1 data]$

  21, entered the library a number of small operations

[postgres@web1 data]$ psql    #进入库
psql (10.5)
Type "help" for help.

postgres = # \ password # password
the Enter new new password:
the Enter IT Again:
Postgres the CREATE DATABASE name = #; # Create a library
the CREATE DATABASE
Postgres = # \ du # view the user
                                  List of the Roles
 Role name | the Attributes | Member of
---- ------- + ------------------------------------------ + ----------- ------------------
 Postgres | Superuser, the Create Role, the Create DB, the Replication, the RLS Bypass | {}

postgres=#
postgres=# \l    #查看数据库列表
                                  List of databases
  Name    |  Owner  | Encoding |  Collate  |    Ctype    |  Access privileges 
-----------+----------+----------+-------------+-------------+-----------------------
 name      | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 |
 postgres  | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
          |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
          |          |          |            |            | postgres=CTc/postgres
(4 rows)

= # Postgres
Postgres = # the Create the User the Test superuser password '123456'; # create a user ID and password
the CREATE the ROLE
Postgres = #

This will generally be deployed over.

Guess you like

Origin www.linuxidc.com/Linux/2019-06/158906.htm