Installation postgresql11.5

 

install as root

Create a user 

compiled a successful installation, the next step is to create a regular user because the default superuser (root) can not start postgresql, so you need to create a normal user to start the database, create a user execute the following command: 

[root @ localhost build_dir ] # groupadd postgres 
[root @ localhost build_dir] # useradd - G postgres postgres 
[root @ localhost build_dir] # passwd postgres 

Next, set permissions, assign all data directory pg postgres user, execute the following command: 

[root @ localhost build_dir ] # chown -R Postgres: Postgres / usr / local / pgSQL 

to create the directory 

[root @ localhost build_dir] # mkdir -p / mnt / db1 / PGDATA / pgSQL / mnt / db1 / PGDATA / pgtbs / mnt / db1 / ARCHIVELOG / Backups 
[build_dir the root @ localhost] # the chmod -R & lt 775 / mnt / DB1
[root@localhost build_dir]# chown -R postgres:postgres /mnt/db1

设置环境变量

[root@localhost build_dir]# vi /home/postgres/.bash_profile

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export PGPORT=8432
export PGHOME=/usr/local/pgsql
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 "the Y% m%%% D% H M" ' 
Export the LD_LIBRARY_PATH = $ PGHOME / lib: $ the LD_LIBRARY_PATH 
Export the PGHOST = $ PGDATA is 
Export PGUSER = Postgres 
Export PGDATABASE = Postgres 

the PATH = the PATH $: $ the HOME / .local / bin : $ the HOME / bin: $ PGHOME / bin 
Export the PATH 

execute the following command to take effect: 

[root @ localhost build_dir] # Source /home/postgres/.bash_profile

 

 

 

 

 

 

ready

yum install -y 
gcc gcc-c++  
openssl openssl-devel
readline readline-devel 
zlib zlib-devel 
llvm5.0 llvm5.0-devel 
libxml2-devel 
libxslt-devel 
libicu-devel 

python-devel
tcl-devel 
systemd-devel 
openldap-devel 
pam-devel 

clang 
perl-ExtUtils-Embed 
epel-release 


 

 

configure

# cd build_dir/
vim ../src/Makefile.global.in
修改以下行:
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
修改为:
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -emit-llvm -c

-- --prefix 指定默认安装路径
[root@localhost build_dir]# ../configure 
--prefix=/usr/local/pgsql 
--enable-nls 
--with-perl 
--with-python 
--with-tcl 
--with-gssapi 
--with-llvm LLVM_CONFIG='/usr/lib64/llvm5.0/bin/llvm-config '  
--with- ICU 
 --with- OpenSSL 
 --with- PAM 
 --with- LDAP 
 --with- systemd 
 --with- libxml 
 --with-the libxslt 


after #configure command completes, you will find the configuration file is created config.status

 

 

make 
make  install

 

 

 

 

Database initialization 

switch user 
[build_dir the root @ localhost] # SU - Postgres 
initialized Database 
[Postgres @ localhost ~] $ $ initdb -D PGDATA is -U = Postgres --locale en_US.utf8 - E the UTF8 

    modify the monitoring address as the setting value of listen_addresses * make the whole network monitor, the default port number is 5432, you can also set up their own. 

[Postgres @ localhost ~] $ Vim / mnt / DB1 / PGDATA / pgSQL / the postgresql.conf 
content: 
the listen_addresses = ' * ' 
unix_socket_directories = ' . ' 
Port = 8432 

    modified client authentication methods 

[Postgres @ localhost ~] $ Vim / mnt / db1 / pgdata / pgsql /pg_hba.conf 
add content: 
Host All All 0.0 . 0.0 / 0 MD5 # other users landing 

set firewall rules 

# to switch back to the root user 
[Postgres @ localhost ~ ] $ Exit 
[root @ localhost build_dir] # Firewall -cmd public --zone = = Port---add 8432 / TCP - Permanent 
[build_dir the root @ localhost] # Firewall -cmd - reload 

start database 

[build_dir the root @ localhost] # SU - Postgres 
promoter 
[Postgres @ localhost ~] $ pg_ctl -D / mnt / db1 / PGDATA / pgSQL the -l / mnt / db1 / ARCHIVELOG / pgsql.log Start 
stop 
[root @ localhost postgres] # pg_ctl-D / mnt / DB1 / PGDATA / pgSQL / -s - m STOP FAST 

connection test 

[Postgres @ localhost ~ ] $ the psql 
query for all users 
Postgres = # SELECT * from pg_user; 
Postgres = # SELECT * from pg_roles; 
query permitted 
Postgres = # the SELECT * from information_schema.table_privileges the WHERE GRANTEE = ' CC ' ; 
see which databases have 
Postgres = # \ L 
comparable to the mysql databases Show; 
Postgres = # the SELECT datname from pg_database; 
the equivalent of mysql show tables, public is the default schema name 
Postgres = # the FROM information_schema.tables the WHERE table_schema the SELECT table_name = ' public ' ; 
comparable to describe table_name mysql's, ' table_name ' is the name of the table to be queried 
Postgres = # the SELECT column_name the FROM information_schema.columns the WHERE table_name = ' table_name ' ; 
exit 
Postgres = # \ q 

psql PostgreSQL is a client program to connect to PostgreSQL database, we need to specify the following:

     -d or - dbname database name
     -h or - host hostname
     -p or - port port number, default 5432 port
     -U or - username username 
    [postgres @ localhost~] $ -H localhost the psql -p 8432 - the U-postgres 

provided postgres user password 

[postgres @ localhost ~ ] $ the psql 
postgres = # postgres the WITH ENCRYPTED PASSWORD the ALTER the USER ' new new password ' ; 
postgres = # \ Q 
[postgres @ localhost ~] -H localhost the psql -p $ 8432 - the U-Postgres 

disposed boot from the start 

    the startup configuration 

Vim / usr / lib / systemd / System / postgresql- . 11 .service 
add content: 
[Unit] 
the Description = the PostgreSQL . 11 Database Server 
Documentation = HTTPS: / /www.postgresql.org/docs/11/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Location of database directory
Environment=PGDATA=/mnt/db1/pgdata/pgsql/

# 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

Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

# ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
# ExecStart=/usr/local/pgsql9.4/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
# ExecStop. = / usr / local / pgsql9 4/ bin / STOP pg_ctl -D PGDATA is $ {} -s - m FAST 
# ExecReload . = / usr / local / pgsql9 . 4 / bin / reload pg_ctl -D PGDATA is $ {} - S 
KillMode = Mixed 
KillSignal = SIGINT 

# the SET the Do not the any timeout value, SO that systemd by Will not the kill postmaster 
# During Crash Recovery. 
TimeoutSec = 0 

[the Install] 
WantedBy = Multi- user.target 

    add executable permissions 

[root @ localhost Postgres] # chmod  754 / usr / lib / systemd / System / postgresql- . 11 .service 

    disposed boot from the start 

autostart
[root @ localhost Postgres] # systemctl enable PostgreSQL - 11 .service 
start 
[root @ localhost Postgres] # systemctl Start PostgreSQL - 11 .service 
stop a service 
[root @ localhost Postgres] # systemctl STOP PostgreSQL - 11 .service 
does not start automatically 
[ Postgres @ localhost root] # systemctl disable PostgreSQL - 11 .service 
check the service status (service details) 
systemctl status PostgreSQL - 11 .service 
check the service status (display only if the Active) 
systemctl iS -active postgresql- 11 .service 
show all started the service 
systemctl List -units --type service =

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/igoodful/p/11830219.html