PostgreSQL is an open source Object-Relational Database Management System (ORDBMS), based on the original POSTGRE source code from the University of California, Berkeley, which supports most SQL standards and offers many modern features.
PostgreSQL uses a C/S architecture. The server-side process (called postgres
) manages the database files, receives connections from the client, and performs database operations on behalf of the client; the client-side process initiates connections to the server and sends database operation commands. The server and client processes can be located on the same host or on different hosts, and if they are located on different hosts, they communicate over TCP/IP. The PostgreSQL server can handle concurrent connections from clients at the same time. This is achieved by starting a new process for each connection, and the new process does not affect the work of the original postgres
process.
In this article, we will do a source installation of PostgreSQL 13.3
on a CentOS 7.6
host and use it briefly.
1 Hosting Requirements
PostgreSQL can be run on most modern Unix-compatible platforms, and this host CentOS 7.6
meets the requirements.
The following packages are required to build PostgreSQL.
a) GNU make version 3.80+
b) ISO/ANSI C compiler (latest GCC recommended)
c) tar for decompressing the source code zip file
d) GNU Readline Library
is used by the PostgreSQL command line tool psql
to record each command typed, which can then be reused using the arrow keys.
e) zlib compression library
Supports pg_dump
and pg_restore
compression archives.
2 PostgreSQL installation
Before the following command is executed, the current user is the non-root
sudoer account larry
.
a) Get the source code zip file
Go to the user root directory, download the PostgreSQL 13.3
source code zip file, and unzip it to the current directory when you are done.
b) Configure, build, test, and install
After the previous step, a directory postgresql-13.3
will be created in the current directory, which you can enter to configure, build, test, and install.
Check the installation directory /usr/local/pgsql/
and find that it contains several folders.
c) Configure the data directory and start
It is recommended to run PostgreSQL with a separate account (postgres
) that only has access to the data managed by the server (in particular, this account should not have access to the PostgreSQL executables either, in case they are tampered with by infected service processes) and does not share data with other daemons.
The following command creates a new account postgres
with the current sudoer user larry
, creates a new /pusr/local/pgsql/data
data folder and gives control permissions to postgres
.
Next, switch the user to postgres
, initialize the database, and start the service.
At this point, the PostgreSQL service has been started.
d) Setting up boot-up
Edit the /etc/rc.d/rc.local
file with root privileges and add the startup command.
|
|
|
|
3 Simple use of PostgreSQL
Create a database test
and use the PostgreSQL interactive command line program psql
to test the connection.
|
|
At this point, we have finished installing and testing the source code for PostgreSQL.