current position:Home>PostgreSQL DBA quick start - source compilation and installation

PostgreSQL DBA quick start - source compilation and installation

2022-06-24 09:53:44post_ yuan

This article introduces through PostgreSQL The official source installation package is compiled and installed to get started quickly PostgreSQL database .


  1. install gmake, adopt gmake -v see
  2. install gcc, adopt which gcc see
  3. install tar, adopt tar --help see
  4. install GNU readline library, Support up and down buttons 、 Fallback key, etc , adopt rpm -qa | grep readline see
  5. install Zlib compression library, For compression function

Create user

  1. id postgres - Check to see if there is postgres user
  2. groupadd postgres - add to postgres Group
  3. useradd -g postgres postgres - add to postgres user
  4. passwd postgres - modify postgres password
  5. mkdir -p /data/postgres/13.2/ - Create database directory
  6. chown -R postgres:postgres /data/ - Modify database directory permissions

Install and start the database

  1. su – postgres - Switch postgres user
  2. wget xxx.tar.gz - Download source package
  3. tar -xzvf xxx.tar.gz - decompression
  4. cd postgresql-13.2 - Toggle directory
  5. ./configure –preifx=/data/postgres/13.2/ - perform configure
  6. gmake world - perform gmake
  7. gmake install-world - perform gmake install
  8. /data/postgres/13.2/bin/initdb -d /data/postgres/13.2/data - Initialize database
  9. /data/postgres/13.2/pg_ctl -D /data/postgres/13.2/data -l logfile start - Start database

Modify environment variables

The purpose is to eliminate the need to specify an executable ( Such as psql、pg_ctl etc. ) The absolute path of

  1. modify postgres User ~/.bash_profile, It can also be modified directly ~/.bashrc
    export PATH
    export PGDATA
  2. source ~/.bashrc
  3. perform psql Verify that the environment variable modification takes effect

Modify database configuration

  1. stay /data/postgres/13.2/data/pg_hba.conf in , Add the following line :
    host all all md5
    The above means for all uses IPV4 The client machine of , Allow any IP, Any user can initiate access to the database , But the database user password must be provided , The authentication method is through MD5 Encryption Authentication .

  2. stay /data/postgres/13.2/data/data/postgresql.conf in , modify
    #listen_addresses=’localhost’ by listen_addresses=’*’
    Need to restart
    pg_ctl restart -m fast
    Indicates that any client is allowed to access

How to start and stop a database

  1. ps -ef | grep postges - Check whether the database is running
  2. pg_ctl stop -m fast - Stop database
  3. pg_ctl start -D /data/postgres/13/2/data -l ~/startup.log - Start database
  4. pg_ctl status - Check database status

be familiar with psql Command line tools

which psql
psql --help
psql -h localhost -p 5432 -d postgres -U postgres
\c - Check which user is connected to which database
\d – See the table
\d <tablename> - View table structure
\i ext.sql - Execute a file , amount to Oracle Medium @
\h - Check all commands
\h create table - see create table Help document for
select version(); - View version
\l - View all database information
\l+ - View database information and size information
select pg_postmaster_start_time();
\du - View user information
\dt+ - Check the table size
\di+ - View index information
\dv - View view
\df - View functions

copyright notice
author[post_ yuan],Please bring the original link to reprint, thank you.

Random recommended