PostgreSQL Database Management - Chapter 1 Installation and Configuration

PostgreSQL Database Management

Chapter 1 Installation and Configuration

Outline

PostgreSQL is a very powerful, open source code for client / server relational database management system (RDBMS). Data types (such as JSON and JSONB type, array type) supports rich and custom type. The default page size PostgreSQL memory is 8kB.

 

PostgreSQL has the following key features:

1 Good SQL language support, support the ACID , associate integrity, database transactions, Unicode multilingual.

2 designing high concurrent read and write and do not clog

3 supports a number of types of database models: relational, document type (such as JSON and JSONB type, array type), Key / value types.

1 install PostgreSQL

    1. Installation PostgreSQL packet under linux rpm

1 installation repository RPM:

Yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

RPM package install server 2

yum list postgresql11-server.x86_64

 3 install the client package:

yum list postgresql11.x86_64 

4 to initialize the database and enable automatic startup:

/ usr / pgsql-11 / bin / postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11

 

PostgreSQL 1.2 linux installation of the source package

1 system environment to establish

gcc, bison, gcc-c++, readline, readline-devel, zlib, zlib-devel

yum install *gcc* -y

[root@Redhat7 ~]# yum install *bison* -y

[root@Redhat7 ~]# yum install *readline* -y

[root@Redhat7 ~]# yum install *zlib* -y  

2 and linux system optimization

ulimit functions: control of the resource shell program

In the time following the deployment of Linux applications, sometimes encounter Socket File /: Can not open so many files in question; this value will also affect the maximum number of concurrent server, in fact, there is a Linux file handle limit, but Linux default not very high, usually 1024, with the production server is actually very easy to reach this number. Below that it is how to correct the system defaults by positive solution configuration.

/etc/security/limits.conf

soft nproc: maximum number of processes available to a single user (more than warn);

hard nproc: maximum number of processes available to a single user (more than being given);

soft nofile: to open the maximum number (more than warn) file descriptor;

hard nofile: the maximum number of open file descriptors (more than being given);

# End of f11e

* soft  nof1le  1024000

* Hard nofile 1024000

* soft  nproc  1024000

* hard  nproc 1024000

 

[root@Redhat7 ~]# cat /etc/security/limits.d/20-nproc.conf

# Default limit for number of user's processes to prevent

# accidental fork bombs.

# See rhbz #432903 for reasoning.

 

*          soft    nproc     4096

root       soft    nproc     unlimited

changed to

 

*  soft nproc  1024000

*  hard nproc  1024000

root       soft    nproc     unlimited

 

 

 

3 Create the postgres user, and create the installation directory

[root@Redhat7 ~]# useradd postgres

[Root @ Redhat7 ~] # mkdir /opt/pgsql11.4 create home directories PG

[Root @ Redhat7 ~] # mkdir / pgdb create data directory PG

[root@Redhat7 ~]# chown -R postgres:postgres /opt/pgsql11.4/

[root@Redhat7 ~]# chown -R postgres:postgres /pgdb

 

4 Installing PostgreSQL

[root@Redhat7 pgsql11.4]# tar -zxvf postgresql-11.4.tar.gz

[root@Redhat7 postgresql-11.4]# ./configure --prefix=/opt/pgsql11.4

make

make install

PostgreSQL installation complete.

Port prefix = PREFIX - installation most frequently modified path

Mouth with- blocksize = BLOCKSIZE - database blocksize, the default 8KB

OLAP scene at this value can be increased to 32kB, in order to improve the performance of OLAP, it is recommended to use 8kB defaults in OLTP scenarios.

Port with-segsize = SEGSIZE - segment table file size, default 1GB

Mouth with-llvm - based JIT compiler to use Ivm

Port --with-wal-blocksize = BLOCKSIZE: WAL specify the block size of the file, the default is 8kB.

Port --with-wal-segsize = SEGSIZE: WAL specify a single file size, default is 16MB.

5 configuration environment variable

Relatively wide

we /home/postgres/.bash_profile

Add Content:

export PGPORT = 8432

export PGHOME=/usr/pgsql-11

export PGDATA=/mnt/db1/pgdata/pgsql

export PATH=$PGHOME/bin:$PATH

export MANPATH=$PGHOME/share/man:$MANPATH

export LANG = en_US.UTF-8

export DATE='date +"%Y%m%d%H%M"'

export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

export PGHOST=$PGDATA

export PGUSER=postgres

usable

PGHOME=/opt/pgsql11.4

export PGHOME

PGDATA=/pgdb

export PGDATA

export PATH=$PGHOME/bin:$PATH

export PATH

6 initialize the database

Command to initialize the database cluster using initdb

A -D: database cluster home directory

--E: database character encoding

--wal-segsize: WAL log file size

- -U: specify the superuser

 

initdb -D /pgdb/

[postgres@RHCE7 ~]$ initdb -D /pgdb/

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 "zh_CN.UTF-8".

The default database encoding has accordingly been set to "UTF8".

initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"

The default text search configuration will be set to "simple".

 

Data page checksums are disabled.

 

fixing permissions on existing directory /pgdb ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting default timezone ... PRC

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 /pgdb/ -l logfile start

 

[postgres@RHCE7 ~]$   pg_ctl -D /pgdb/ -l logfile start

waiting for server to start.... done

server started

7 at startup

 

[root@RHCE7 ~]# vim  /usr/lib/systemd/system/postgresql-11.service

 

[Unit]

Description=PostgreSQL database server

After=network.target

 

[Service]

Type=forking

 

User=postgres

Group=postgres

 

# Port number for server to listen on

Environment = PGPORT = 5432

 

# Location of database directory

Environment=PGDATA=/pgdb/

 

# Where to send early-startup messages from the server (before the logging

# options of postgresql.conf take effect)

# This is normally controlled by the global default set by systemd

# StandardOutput=syslog

 

# Disable OOM kill on the postmaster

OOMScoreAdjust=-1000

 

#ExecStartPre=/opt/pgsql11.4/bin/postgresql-check-db-dir ${PGDATA}

ExecStart=/opt/pgsql11.4/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300

ExecStop=/opt/pgsql11.4/bin/pg_ctl stop -D ${PGDATA} -s -m fast

ExecReload=/opt/pgsql11.4/bin/pg_ctl reload -D ${PGDATA} -s

 

# Give a reasonable amount of time for the server to start up/shut down

TimeoutSec=300

 

[Install]

WantedBy=multi-user.target

 

 

[root@RHCE7 ~]# systemctl enable /usr/lib/systemd/system/postgresql-11.service

Init 6 reboot testing

 

[root@RHCE7 ~]# systemctl status postgresql-11.service

● postgresql-11.service - PostgreSQL database server

   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)

   Active: active (running) since 日 2019-09-15 00:37:04 CST; 3min 47s ago

  Process: 936 ExecStart=/opt/pgsql11.4/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)

1.3PostgreSQL remote access (linux version)

linux version of postgresql default can not directly access their remote database is therefore a need to modify postgreSQL database configuration for remote access.

Specific operation is as follows: the following modifications postgresql.conf

At the end user to add parameters:

listen_address = '*', be careful not to be commented out

Enable password authentication

# Password_encryption = md5 amended as password_encryption = md5

 

Modify the contents of the pg_hba.conf file:

Users can access the ip segment

In the end of the file added: host all all 0.0.0.0/0 trust

You can also host all all all trust

 

Restart postgreSQL database: After a successful start, then connect the remote

 

Published 37 original articles · won praise 0 · Views 2400

Guess you like

Origin blog.csdn.net/syjhct/article/details/100867439
Recommended