Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install PostgreSQL on Linux

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to install PostgreSQL on Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to install PostgreSQL on Linux.

Environment

Here is to learn PG from scratch, in order to adapt to the trend two years later, so I choose the latest version

Redhat 7.8

PostgreSQL 12.2 source code

download

Open the PostgreSQL website https://www.postgresql.org/ and click Download on the menu bar.

You can click on the version you need according to your needs. Here, in order to better learn PG and not lag behind other big names, I choose to download the latest version of the source code.

Installation

Upload and decompress

[root@node1 soft] # bzip2-d postgresql-12.2.tar.bz2 [root@node1 soft] # tar-xvf postgresql-12.2.tar postgresql-12.2/ postgresql-12.2/.dir-locals.el postgresql-12.2/contrib/ postgresql-12.2/contrib/tcn/ postgresql-12.2/contrib/tcn/tcn.control... (omit output) [root@node1 soft] # ls-lrt total 131200 drwxrwxrwx 6 1107 1107 Feb 10 17:29 postgresql-12.2-rw-r--r-- 1 root root 134348800 Apr 30 05:29 postgresql-12.2.ta

Install the yum package

Yum-y install readline-develyum-y install readline

Avoid. / configure Times error

Configure

[root@node1 postgresql-12.2] #. / configure checking build system type... X86_64-pc-linux-gnuchecking host system type... X86_64-pc-linux-gnuchecking which template to use... Linuxchecking whether NLS is wanted... Nochecking for default port number... 5432checking for block size... 8kB... ... (omit output) checking for fop... Nochecking thread safety of required library functions... Yeschecking whether gcc-std=gnu99 supports-Wl,--as-needed... Yesconfigure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39) configure: using CFLAGS=-Wall-Wmissing-prototypes-Wpointer-arith-Wdeclaration-after-statement-Werror=vla-Wendif-labels-Wmissing-format-attribute-Wformat-security-fno-strict-aliasing-fwrapv-fexcess-precision=standard-O2configure: using CPPFLAGS=-D_GNU_SOURCE configure: using LDFLAGS=-Wl -- as-neededconfigure: creating. / config.statusconfig.status: creating GNUmakefileconfig.status: creating src/Makefile.globalconfig.status: creating src/include/pg_config.hconfig.status: creating src/include/pg_config_ext.hconfig.status: creating src/interfaces/ecpg/include/ecpg_config.hconfig.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.sconfig.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_ Sema.cconfig.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.cconfig.status: linking src/include/port/linux.h to src/include/pg_config_os.hconfig.status: linking src/makefiles/Makefile.linux to src/Makefile.por

Make & & make install

[root@node1 postgresql-12.2] # makemake-C. / src/backend generated-headersmake [1]: Entering directory `/ soft/postgresql-12.2/src/backend'make-C catalog distprep generated-header-symlinksmake [2]: Entering directory` / soft/postgresql-12.2/src/backend/catalog'... .. (omit output) make [2]: Nothing to be done for `all'.make [2]: Leaving directory `/ soft/postgresql-12.2/src/test/perl'make [1]: Leaving directory` / soft/postgresql-12.2/src'make-C config allmake [1]: Entering directory `/ soft/postgresql-12.2/config'make [1]: Nothing to be done for `all'.make [1]: Leaving directory` / soft/postgresql-12.2/config'All of PostgreSQL successfully made. Ready to install. [root@node1 postgresql-12.2] # make installmake-C. / src/backend generated-headersmake [1]: Entering directory `/ soft/postgresql-12.2/src/backend'make-C catalog distprep generated-header-symlinksmake [2]: Entering directory` / soft/postgresql-12.2/src/backend/catalog'make [2]: Nothing to be done for `distprep'.make [2]: Nothing to be done for `generated-header-symlinks'.... (omitting output) make-C config installmake [1]: Entering directory `/ soft/postgresql-12.2/config'/usr/bin/mkdir-p'/ usr/local/pgsql/lib/pgxs/config'/usr/bin/install-c-m 755. / install-sh'/usr/ local/pgsql/lib/pgxs/config/install-sh'/usr/bin/install-c-m 755. / missing' / usr/local/pgsql/lib/pgxs/config/missing'make [ 1]: Leaving directory `/ soft/postgresql-12.2/config'PostgreSQL installation complete

Create a user and configure a password

[root@node1 postgresql-12.2] # useradd postgres [root@node1 postgresql-12.2] # passwd postgresChanging password for user postgres.New password: BAD PASSWORD: The password contains the user name in some formRetype new password: passwd: all authentication tokens updated successfully

Create a data directory and authorize

[root@node1 postgresql-12.2] # mkdir-p / data/pg_ data [root @ node1 postgresql-12.2] # chown postgres:postgres-R / data [root@node1 postgresql-12.2] # cd / usr/local [root@node1 local] # lltotal 0drwxr-xr-x. 2 root root 6 Dec 14 2017 bindrwxr-xr-x. 2 root root 6 Dec 14 2017 etcdrwxr-xr-x. 2 root root 6 Dec 14 2017 gamesdrwxr-xr-x. 2 root root 6 Dec 14 2017 includedrwxr-xr-x. 2 root root 6 Dec 14 2017 libdrwxr-xr-x. 2 root root 6 Dec 14 2017 lib64drwxr-xr-x. 2 root root 6 Dec 14 2017 libexecdrwxr-xr-x 6 postgres postgres 56 Apr 30 05:53 pgsqldrwxr-xr-x. 2 root root 6 Dec 14 2017 sbindrwxr-xr-x. 5 root root 49 Apr 16 12:09 sharedrwxr-xr-x. 2 root root 6 Dec 14 2017 src [root@node1 local] # chown postgres:postgres-R pgsq

Configure postgres user

[postgres@node1 ~] $cat .bash _ profile export PATH=$PATH:/usr/local/pgsql/binexport PGDATA=/data/pg_ data [Postgres @ node1 ~] $source .bash _ profile

Initialize the database

[postgres@node1 ~] $initdb-D / data/pg_data/The files belonging to this database system will be owned by user "postgres" .This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8" default database encoding has accordingly been set to "UTF8" default text search configuration will be set to "english" .data page checksums are disabled.fixing permissions on existing directory / data/pg_data. Okcreating subdirectories... Okselecting dynamic shared memory implementation... Posixselecting default max_connections... 100selecting default shared_buffers... 128MBselecting default time zone... America/New_Yorkcreating configuration files... Okrunning bootstrap script... Okperforming post-bootstrap initialization... Oksyncing data to disk... Okinitdb: warning: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option-A, or--auth-local and-- auth-host, the next time you run initdb.Success. You can now start the database server using: pg_ctl-D / data/pg_data/-l logfile star

Start the database

[postgres@node1] $pg_ctl-D / data/pg_data/ startwaiting for server to start....2020-04-306 EDT 34 EDT [53149] LOG: starting PostgreSQL 12.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit2020-04-300 06 EDT 34 EDT [53149] LOG: listening on IPv6 address ":: 1" Port 54322020-04-300 06 port 34 database system was shut down at 29.841 EDT [53149] LOG: listening on IPv4 address "127.0.0.1", port 54322020-04-30 06 database system was shut down at 34 database system was shut down at 29.844 EDT [53149] LOG: listening on Unix socket "/ tmp/.s.PGSQL.5432" 2020-04-30 06 LOG 29.856 EDT [53150] database system is ready to accept connections doneserver starte: database system was shut down at 2020-04-30 06:29:52 EDT2020-04-30 06 LOG:

Shut down the database

[postgres@node1] $pg_ctl-D / data/pg_data/ stopwaiting for server to shut down....2020-04-3006 LOG: background worker "logical replication launcher" (PID 53156) exited with exit code 12020-04-306 exited with exit code 12020-04-306 EDT [53151] LOG: shutting down2020-04-3006 shutting down2020-04-306 EDT [53149] LOG: database system is shut down doneserver stopped I believe you have a deeper understanding of "how to install PostgreSQL on Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 223

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report