- Learning PostgreSQL 11
- Salahaldin Juba Andrey Volkov
- 422字
- 2021-07-02 13:11:44
Installing PostgreSQL on Linux via source
Installing PostgreSQL form source code is straightforward using configure, make, and make install. First, you need to make sure that all the prerequisite libraries, as well as the C++ compiler, are installed. The installation instruction might change based on the Linux version and installed libraries.
The following installation instructions are performed on a fresh installation of Ubuntu Bionic. On Ubuntu, you can get and install the prerequisites, including the compiler, zlib, and readline libraries, via the following command:
sudo apt-get install build-essential
sudo apt-get install zlib1g-dev libreadline6-dev
You can get the source code of PostgreSQL from the PostgreSQL server FTP site and extract it as follows:
wget https://ftp.postgresql.org/pub/source/v11.1/postgresql-11.1.tar.bz2
tar -xvf postgresql-11.1.tar.bz2
To configure PostgreSQL, run the ./configure command; note that, if there are missing libraries, configure will raise an error:
cd postgresql-11.1
./configure
After a successful configuration, to build PostgreSQL run make:
make
To install PostgreSQL, switch to a privileged user account, such as root, and run make install:
sudo su make install
At this point, PostgreSQL is installed. The binaries can be found at /usr/local/pgsql. PostgreSQL runs using the postgres user . In order to run the server, we need to create a user account, as follows:
adduser postgres
The last step of the installation is to create a database cluster and run PostgreSQL for this cluster. Perform the following steps:
- Create a folder to store the database cluster information.
- Change the folder permissions and make the owner the postgres user. The postgres user account will be used to run the PostgreSQL server.
- Initialize the cluster using the initdb command. initdb needs the folder location of the cluster.
- Run PostgreSQL using the postgres command. The postgres command needs the cluster folder location:
$mkdir /usr/local/pgsql/data chown postgres /usr/local/pgsql/data
$su - postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
The previous installation instructions are quite minimal. PostgreSQL allows the user to configure the binary location, compiler flags, libraries, and so on. In the preceding code, the defaults are used. To verify our installation, you can connect to the server as follows:
/usr/local/pgsql/bin/psql postgres
psql (11.1)
Type "help" for help.
postgres=# SELECT version();
version
------------------------------------------------------------------------------------------------------
PostgreSQL 11.1 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit
(1 row)
Finally, installing PostgreSQL from source code doesn't amend the system environment path or create a Linux service with systemd. To stop the PostgreSQL server, simply exit the Terminal. For production environments, it's better to use ready in binaries.
- Boost程序庫完全開發指南:深入C++”準”標準庫(第5版)
- Hands-On Data Structures and Algorithms with JavaScript
- Raspberry Pi for Secret Agents(Third Edition)
- ASP.NET動態網頁設計教程(第三版)
- Flash CS6中文版應用教程(第三版)
- Mastering Apache Maven 3
- C語言程序設計
- SciPy Recipes
- MySQL程序員面試筆試寶典
- Java Web從入門到精通(第2版)
- Web前端開發最佳實踐
- 量子計算機編程:從入門到實踐
- 少兒編程輕松學(全2冊)
- Learning Redux
- Java Web 從入門到項目實踐(超值版)