1辆床、由于版本問題,導致安裝麻煩至壤,卸載-安裝-卸載-刪除原來不同文件夾同樣的文件---
有效參考
postgreSQL15發(fā)布减噪,難掩激動快速嘗鮮_11672417的技術博客_51CTO博客
Community DL Page (enterprisedb.com)
postgresql數(shù)據(jù)庫報“connections on Unix domain socket "/tmp/.s.PGSQL.5432"?”/temp/.s.pgswl.5432臨風賞月的博客-CSDN博客
麒麟信安V3.4 安裝PG15的過程_11519070的技術博客_51CTO博客
安裝postgres
1、python 錯誤導致yum不能使用:export LD_LIBRARY_PATH="/usr/lib64:/usr/lib:${LD_LIBRARY_PATH}"
1.1 echo "export LD_LIBRARY_PATH="/usr/lib64:/usr/lib:${LD_LIBRARY_PATH}" >> /etc/profile
1.2 source /etc/profile
2鼻吮、更新centos源 yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
3育苟、yum update
4、安裝pgseql yum install -y postgresql15 postgresql15-server postgresql15-libs postgresql15-contrib
5椎木、安裝插件 yum install postgresql-contrib15.1
6违柏、安裝net-tools
7、查看端口:netstat -anp | grep 5432
# 導入osm
1香椎、yum install osm2pgsql
2漱竖、下載osm數(shù)據(jù)
3、切換賬戶 su - postgres
4畜伐、創(chuàng)建pgsql的osm database
5馍惹、卸載:yum remove postgresql-9.2.24-8.el7_9.x86_64
6、卸載:yum remove postgresql-libs-9.2.24-8.el7_9.x86_64
7玛界、export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib
8万矾、osm2pgsql --slim -d osm --hstore --multi-geometry --number-processes 8 --tag-transform-script /home/osm/openstreetmap-carto-4.20.0/openstreetmap-carto.lua --style /home/osm/openstreetmap-carto-4.20.0/openstreetmap-carto.style /home/osm/china-latest.osm.pbf
sudo passwd postgres
su – postgres
psql -c "ALTER USER postgres WITH PASSWORD ‘postgres';"
systemctl stop postgresql-15
systemctl status postgresql-15
systemctl start postgresql-15
systemctl enable postgresql-15
/usr/local/pgsql-15.1/bin
pg_ctl register -N PostgreSQL -D "/var/lib/pgsql/15/data"
export HGDB_HOME=/usr/local/pgsql-15.1
export PATH=$PATH:$HGDB_HOME/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql-15.1/lib
插件安裝
Docker安裝
ubuntu20.04
# 按照官網(wǎng)安裝,直接安裝15即可
sudo apt update
sudo apt install postgresql postgresql-contrib
# 查看版本
sudo -u postgres psql -c "SELECT version();"
#
查看安裝狀態(tài)
ps aux | grep postgres
netstat -npl | grep postgres
ss -nlt | grep 5432
# 重啟服務
sudo service postgresql restart
su - postgres -c "/usr/lib/postgresql/15/bin --username=postgres --encoding=UTF8 --lc-collate=C --lc-ctype=en_US.utf8 --data-checksums -D /home/lzg/data"
用戶需要輸入密碼:
su - postgres 如果報錯:su: Authentication failure
則:sudo passwd postgres #sudo passwd -d postgres
#兩次輸入密碼慎框。良狈。 1234
#再次使用該用戶 1234
#再次進入即可:su - postgres
卸載
sudo find / -name "postgres*"|xargs rm -f
初始化數(shù)據(jù)庫
sudo rm -rf /var/lib/postgresql/15/main
sudo mkdir /var/lib/postgresql/15/main
sudo chmod 775 /var/lib/postgresql/15/main
sudo chown postgres /var/lib/postgresql/15/main
cd /usr/lib/postgresql/15/bin/
./initdb --locale $LANG -E UTF8 -D /var/lib/postgresql/15/main
./pg_ctl -D /var/lib/postgresql/15/main -l logfile start
# "local" is for Unix domain socket connections only
local all all peer
#docker 安裝
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo apt update
apt list -a docker-ce
sudo systemctl status docker
sudo usermod -aG docker $USER
使用
1、數(shù)據(jù)卷重用
sudo docker volume create pgdata
sudo docker volume inspect pgdata
2笨枯、啟動docker
docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -v pgdata:/var/lib/postgresql/data -d postgres
sudo docker run -e POSTGRES_PASSWORD=postgres -p 5432:5432 -v pgdata:/var/lib/postgresql/data ubuntu/postgres
sudo docker exec -it eda7995239c0 /bin/bash
run薪丁,創(chuàng)建并運行一個容器遇西;
--name,指定創(chuàng)建的容器的名字窥突;
-e POSTGRES_PASSWORD=password努溃,設置環(huán)境變量,指定數(shù)據(jù)庫的登錄口令為password阻问;
-p 54321:5432梧税,端口映射將容器的5432端口映射到外部機器的54321端口
進入容器
apt-get update && apt-get install lsb-core
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
3、安裝插件
apt install postgresql-14-pgrouting
apt install postgresql-14-postgis-3
4称近、docker 備份
sudo docker ps 獲得正在運行的id:80d4159c23ad
sudo docker commit -a "gg <xxx@tsari.tsinghua.edu.cn>" -m "pg14,add posgis pgrouting" 80d4159c23ad postgres:v2
5第队、啟動
sudo docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -v pgdata:/var/lib/postgresql/data postgres:v2
后面
sudo docker start postgres
6、測試插件:
CREATE EXTENSION PostGIS
CREATE EXTENSION pgRouting
hstore安裝
需要安裝contrib刨秆,使用apt-install安裝凳谦,postgresql15-contrib
如果安裝失敗,則
- wget postgresql15.1源碼
- 解壓縮
- ./configure --prefix=$PWD/install --with-pgport=5432 --with-python --with-contrib --without-readline
- cd contrib
- make all$make install
- 生成的文件拷貝到安裝目錄/usr/local/pgsql-15.1/ (里面的bin衡未,lib,share)
- create extension hstore;測試成功