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 Postgresql10.5 and PostGIS on Centos 7

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is about how to install Postgresql10.5 and PostGIS on Centos 7. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Setup / etc/resolv.conf

Let linux server have access to the Internet

Check the postgresql source:

Yum list | grep postgresql

First install rpm for PostgreSQL:

Yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos1-10-2.noarch.rpm-y

Yum list | grep postgresql

Install postgresql10-contrib and postgresql10-server.

Yum install postgresql10-contrib postgresql10-server-y

This will add an postgres user to our system.

Cat / etc/passwd

Modify the default data directory

The default data directory for Postgresql is / var/lib/pgsql/ version number / data directory, which requires you to have enough storage space under / var. We will replace it here, assuming that / home has a lot of space.

First create a Postgresql data directory under / home, specify the owner postgres and assign permissions at the same time

Mkdir / home/postgresql_data

Chown postgres:postgres / home/postgresql_data

Chmod 750 / home/postgresql_data

Set the environment variable:

Export PATH=/usr/pgsql-10/bin:$PATH

Export LD_LIBRARY_PATH=/usr/pgsql-10/lib

Export PGDATA=/home/postgresql_data

Switch to the postgres user and initialize the database with initdb, which adds a lot of things under / home/postgresql_data.

Modify the contents of the / usr/lib/systemd/system/postgresql-10.service file to specify the correct PGDATA in # Location of database direcotry:

# Location of database directoryEnvironment=PGDATA=/home/postgresql_data

Configure the database service to boot and start the database service immediately:

Systemctl enable postgresql-10.service

Service postgresql-10 start

Service postgresql-10 status

Change the password:

Passwd postgres

\ l list the current library:

Install PostGIS:

Install a few toolkits first

Yum install wget net-tools epel-release-y

Then install postgis

[root@td-db-t01 ~] # yum install postgis24_10 postgis24_10-client-y

Yum install postgis24_10 postgis24_10-client-y

Install expansion tools

Yum install ogr_fdw10-y yum install pgrouting_10-y

Create a database spatial_testdb

CREATE DATABASE spatial_testdb OWNER postgres

Enter

\ C spatial_testdb

Install the PostGis extension

Spatial_testdb=# CREATE EXTENSION postgis

Spatial_testdb=# CREATE EXTENSION postgis_topology

Spatial_testdb=# CREATE EXTENSION ogr_fdw

You can then verify that the installation was successful

Create a spatial data table

Store city information (cities) and add a column for storage space location

Spatial_testdb=# CREATE TABLE cities (id varchar (20), name varchar (50))

Spatial_testdb=# SELECT AddGeometryColumn ('cities',' the_geom', 4326, 'POINT', 2)

Query

Spatial_testdb=# SELECT * FROM cities

Spatial_testdb=# SELECT id, ST_AsText (the_geom), ST_AsEwkt (the_geom), ST_X (the_geom), ST_Y (the_geom) FROM cities

Spatial query the distance between cities

Set up a remote connection

Modify the configuration file

First modify / home/postgresql_data/pg_hba.conf to:

Originally:

Change to:

Secondly, modify / home/postgresql_data/postgresql.conf to:

Change to:

Change to:

Then restart the service

Service postgresql-10 restart

Important: turn on the server firewall

Firewall-cmd-- add-service=postgresql-- permanent Open postgresql Services

Firewall-cmd-- reload overloaded firewall

Remote connection

Here use pgAdmin for remote connection, download address: https://www.pgadmin.org/download/pgadmin-4-windows/. Select to create a server, fill in the corresponding content, and fill in the IP of your own server with the host name.

If it is not installed on your system, use the command to install.

Install firewalld Firewall yum install firewalld

Enable the service systemctl start firewalld.service

Turn off Firewall systemctl stop firewalld.service

Power on and start systemctl enable firewalld.service automatically

Turn off the boot brake and start the systemctl disable firewalld.service

Thank you for reading! This is the end of the article on "how to install Postgresql10.5 and PostGIS on Centos 7". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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