PostgreSQL compilation Installation and configuration

Source: Internet
Author: User
Tags auth locale md5 postgresql psql


1. Establish Postgres users

[Email protected] source]# AddUser postgres


2. Download PostgreSQL source code

[Email protected] source]# pwd

/home/postgres/source

[Email protected] source]# wget https://ftp.postgresql.org/pub/source/v9.6.1/postgresql-9.6.1.tar.gz


3. Compile and install PostgreSQL:

[Email protected] source]# pwd

/home/postgres/source

[Email protected] source]# tar zxf postgresql-9.6.1.tar.gz

[Email protected] source]# CD postgresql-9.6.1

[Email protected] postgresql-9.6.1]#/configure--prefix=/usr/local/pgsql9.6.1

[Email protected] postgresql-9.6.1]# Gmake-j 8

[[email protected] postgresql-9.6.1]# gmake Install


4. Initialize the database:

Mkdir-p/data/postgresql5.6/data

Chown-r Postgres.postgres/data/postgresql5.6/data

[Email protected] postgresql-9.6.1]# Su-postgres

[Email protected] data]$

/usr/local/pgsql9.6/bin/initdb--no-locale-d/data/postgresql5.6/data-e utf8-u postgres-w


[Email protected] data]$/usr/local/pgsql9.6/bin/initdb--no-locale-d/data/postgresql5.6/data-e utf8-u postgres-w

The files belonging to this database system is owned by user "Postgres".

This user must also own the server process.

The database cluster is initialized with locale "C".

The default text search configuration is set to "中文版".

Data page checksums is disabled.

Enter new Superuser password: (requires a super User Postgres password)

Enter It again:

Fixing permissions on existing Directory/data/postgresql5.6/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:


/usr/local/pgsql9.6/bin/pg_ctl-d/data/postgresql5.6/data-l logfile Start


/usr/local/pgsql9.6/bin/initdb--no-locale-d/data/postgresql5.6/data-e utf8-u postgres-w

5. Introduction of parameters for initializing database:

Initdb [OPTION] [DataDir]


Options:

-A,--Auth=method: Specify authentication method for local connection

[-D,--Pgdata=] DataDir: Specify the original directory for the database family (must be empty)

-E,--encoding=encoding: Specify the default encoding for the database

--locale=locale: Setting the locale for the database

--no-locale: Equivalent--locale=c

--pwfile=file: Reads the password of the superuser from the file specified

-T,--text-search-config=cfg: Specify the default configuration

-U,--username=username: Specify User name

-W,--pwprompt: Force prompt for password input

-X,--Xlogdir=xlogdir: Specifies the directory file for the transaction log


[[email protected] data]$ ls

Base Pg_clog pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VE Rsion postgresql.auto.conf

Global pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase PG_XL OG postgresql.conf


6, Configuration postgresql.conf

Allow service listening range, 0.0.0.0 allow all IPv4 addresses to be monitored

listen_addresses = ' 0.0.0.0 '

Port = 10637

#用户访问日志格式

log_destination = ' Csvlog '

#启用用户访问日志收集器

Logging_collector = On

# #指定运行日志存放路径, specifying the name of the run log file

log_directory = '/data/postgresql5.6/log '

Log_filename = ' Postgresql-%y-%m-%d_%h%m%s.log '


7, Configuration pg_hba.conf

#只给本地和192.168.0.0 Connection

Host All 127.0.0.1/32 MD5

Host All 192.168.0.0/24 MD5


8. Configure PostgreSQL Environment variables

Add the following to the/etc/profile file:

Pgdata=/data/postgresql5.6/data

pghost=127.0.0.1

Pgdatabase=postgres

Pguser=postgres

pgport=10637

# #PGPASSWORD = "123456"

Path=/usr/local/pgsql/bin: $PATH

Export PGDATA PGHOST pgdatabase pguser PGPORT PATH Pgpassword

environment variable in effect

[Email protected] postgresql-9.6]# Source/etc/profile

[email protected] postgresql-9.6]# which psql

/usr/local/pgsql9.6/bin/psql


9. Configure the dynamic library of PostgreSQL to the search path below

[Email protected] postgresql-9.6]# vim/etc/ld.so.conf.d/pgsql.conf

/usr/local/pgsql/lib

Search Path Effective

[Email protected] postgresql-9.6]# Ldconfig

[Email protected] jumpserver]# Ldconfig-p | grep LIBPQ

Libpqwalreceiver.so (libc6,x86-64) =/usr/local/pgsql9.6/lib/libpqwalreceiver.so

Libpq.so.5 (libc6,x86-64) =/usr/local/pgsql9.6/lib/libpq.so.5

Libpq.so (libc6,x86-64) =/usr/local/pgsql9.6/lib/libpq.so


10. Start PostgreSQL Service

Because we have environment variables configured above, we can start the service like this

[Email protected] postgresql-9.6.1]# Su-postgres

[[email protected] postgresql-9.6]$ pg_ctl start

The command has the same effect as the following statement

[Email protected] postgresql-9.6]$/usr/local/pgsql9.6/bin/pg_ctl-d/data/postgresql5.6/data start


This article from "10931853" blog, declined reprint!

PostgreSQL compilation Installation and configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.