官术网_书友最值得收藏!

  • 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:

  1. Create a folder to store the database cluster information.
  2. Change the folder permissions and make the owner the postgres user. The postgres user account will be used to run the PostgreSQL server. 
  3. Initialize the cluster using the initdb command. initdb needs the folder location of the cluster. 
  4. 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.

主站蜘蛛池模板: 舟山市| 湖北省| 宁乡县| 乌海市| 乌什县| 壤塘县| 政和县| 包头市| 民县| 呼玛县| 江城| 噶尔县| 松溪县| 石狮市| 城口县| 昌黎县| 齐河县| 嘉峪关市| 尚志市| 三原县| 上杭县| 叶城县| 昌吉市| 沙田区| 修水县| 临泽县| 民和| 大庆市| 手游| 邯郸县| 天祝| 钦州市| 修文县| 聂拉木县| 北辰区| 商城县| 河池市| 马山县| 甘洛县| 连江县| 左权县|