- 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.
- 移動UI設(shè)計(微課版)
- SoapUI Cookbook
- Learning Selenium Testing Tools with Python
- Rust編程從入門到實戰(zhàn)
- SQL for Data Analytics
- 深入淺出DPDK
- Hands-On RESTful Web Services with Go
- Python機器學(xué)習(xí)算法與實戰(zhàn)
- Mastering Data Mining with Python:Find patterns hidden in your data
- Spring Data JPA從入門到精通
- Ubuntu Server Cookbook
- Python滲透測試編程技術(shù):方法與實踐(第2版)
- Kotlin程序員面試算法寶典
- Mastering R for Quantitative Finance
- Node.js Web Development