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

What are the installation and startup methods of postgresql

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly explains "what are the installation and startup methods of postgresql". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the installation and startup methods of postgresql"?

Two methods

1. Binary installation (linux is a rpm package, in which yum is also a kind of rpm package, and windows is an exe installation file, which is a little more in practice)

2. Source code installation

Binary installation

Example: centos7_64 platform, database postgresql11, installation using yum

If you don't use yum, you can install it directly using rpm package. Download address of rpm package is https://yum.postgresql.org/rpmchart.php.

1. To install the yum source of RPM is to download a yum source pgdg-redhat-all.repo file of postgresql to the / etc/yum.repos.d directory. With this yum source, you can directly yum install postgresql11 and install the postgresql database.

Yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2. To install the client, execute search first to see what PostgreSQL client is available for installation.

Yum search 'PostgreSQL client'

Yum install postgresql11

3. To install the server, first execute search to see what PostgreSQL server is available for installation. After the following steps are installed, the user postgres will be created automatically and the directory / usr/pgsql-11 will be created automatically

Yum search 'PostgreSQL server'

Yum install postgresql11-server

4. Initialize the database and enable boot auto-startup

/ usr/pgsql-11/bin/postgresql-11-setup initdb

Systemctl enable postgresql-11

Systemctl start postgresql-11

5. View the progress of postgresql

[root@zabbixtest2 ~] # ps-ef | grep postgres

Postgres 1527 1 0 01:13? 00:00:00 / usr/pgsql-11/bin/postmaster-D / var/lib/pgsql/11/data/

6. Connect to postgresql database

Su-postgres

Psql-l

Psql-d postgres

Source code installation

1. Set up the configuration of postgresql users and kernel resources, mainly involving / etc/security/limits.conf and / etc/sysctl.conf files. Similar to oracle, you also need to configure these two files.

2. Extract the tar package, enter the directory, use the root user to execute the following, and install the software to the / postgresql/pgsql directory with the final make install command.

. / configure-- prefix=/postgresql/pgsql

Make

Make install

3. Set the software installation directory / postgresql/pgsql authorized host user to postgresql

4. Edit the .bash_profile file of postgresql users, PATH= / postgresql/pgsql/bin: $PATH, LD_LIBRARY_PATH= / postgresql/pgsql/ lib

5. Initialize the database, either of the last two commands will do

Su-postgresql

Initdb-D / postgresql/pgsql/data

Pg_ctl-D / postgresql/pgsql/data initdb

6. Start the postgresql program. Any of the following is fine. Official documents suggest using pg_ctl.

Postgres-D / postgresql/pgsql/data > logfile 2 > & 1 &

Pg_ctl start-D / postgresql/pgsql/data-l logfile

7. View the progress of postgresql

[root@zabbixtest1 ~] # ps-ef | grep postgres

Postgre+ 803 10 07:10 pts/0 00:00:00 / postgresql/pgsql/bin/postgres-D / postgresql/pgsql/data

8. Connect to the postgresql database and specify to connect to the postgres library

Psql-l

Psql-d postgres

Note: the psql command does not add a port or a database name, which means that the default entry port is 5432 and the database name is the same as the user name of the initial database initdb. For example, if the user name of the initial database initdb is A, then enter the A library by default. The default port of postgresql is 5432, and the default database is postgres, template0, template1.

If the port is not 5432, the error psql: FATAL: role "A" does not exist will be reported.

Because the instance port corresponding to the installation user "A" is other, the Owner of the port 5432 database is not "A"

If there is no "A" library at this time, there will be an error psql: FATAL: database "A" does not exist

Because the user "A" is installed, the "A" library is entered by default, but the "A" library does not exist.

9. Create a database called test

Createdb test

10. View database status

Pg_ctl status-D / postgresql/pgsql/data

11. Close the database

Pg_ctl stop-D / postgresql/pgsql/data

Official documentation Short Version brief steps

. / configure

Make

Su

Make install

Adduser postgres

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 &

/ usr/local/pgsql/bin/createdb test

/ usr/local/pgsql/bin/psql test

At this point, I believe you have a deeper understanding of "what are the installation and startup methods of postgresql?" 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: 0

*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