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

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.

主站蜘蛛池模板: 庆城县| 齐齐哈尔市| 广饶县| 赫章县| 深圳市| 盐山县| 咸阳市| 丹寨县| 繁峙县| 将乐县| 玉门市| 郸城县| 金溪县| 定陶县| 忻城县| 县级市| 大英县| 怀集县| 化德县| 泽普县| 胶南市| 曲阳县| 盐源县| 宁陵县| 友谊县| 宜良县| 庄浪县| 寿光市| 白城市| 临高县| 浦东新区| 余干县| 开平市| 读书| 泸溪县| 中方县| 丽水市| 星座| 娱乐| 秭归县| 东城区|