2012年网站设计方法,wordpress 两栏主题,国家企业信息公示网(广东),网站模板 seo已经有了postgres12#xff0c;记录一下升级从postgres12升级到15的过程及遇到的一些问题#xff0c;我没有备份#xff0c;单纯升级
1、升级过程
深色版本 sudo systemctl stop postgresql 升级PostgreSQL
停止PostgreSQL服务#xff1a; 停止当前版本的PostgreSQL服务…已经有了postgres12记录一下升级从postgres12升级到15的过程及遇到的一些问题我没有备份单纯升级
1、升级过程
深色版本 sudo systemctl stop postgresql 升级PostgreSQL
停止PostgreSQL服务 停止当前版本的PostgreSQL服务以确保在升级过程中没有数据写入。
sudo systemctl stop postgresql安装新版本的PostgreSQL 添加PostgreSQL的官方仓库并安装新版本。
添加PostgreSQL官方仓库
sudo sh -c echo deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main /etc/apt/sources.list.d/pgdg.listwget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -sudo apt-get update安装新版本的PostgreSQL
sudo apt-get install postgresql-15停止新版本的PostgreSQL服务 新版本安装后默认会创建一个新的集群并启动服务。停止新版本的PostgreSQL服务。
sudo systemctl stop postgresql15-main删除旧版本的集群 如果一切正常可以删除旧版本的集群。
sudo pg_dropcluster 12 main --stop启动新版本的PostgreSQL服务 启动新版本的PostgreSQL服务。
sudo systemctl start postgresql15-main2、重要事项
登录权限设置
vim /etc/postgresql/15/main/pg_hba.conf# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
# 这个设置为trust可以直接在本机进入postgres不需要密码
local all postgres trust# TYPE DATABASE USER ADDRESS METHOD# local is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
# 添加一行任何主机可以访问设置为 md5或者scram-sha-256即需要输入密码
host all all 0.0.0.0/0 md5
# IPv4 local connections:
# 设置本地网络连接也需要输入密码
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5允许远程访问和更改端口号
vim /etc/postgresql/15/main/postgresql.conf# - Connection Settings -# 这里默认listen_addresses 没有打开这里没有更改应该是不能进行远程连接的设置为*端口号我设置成5433
listen_addresses * # what IP address(es) to listen on;# comma-separated list of addresses;# defaults to localhost; use * for all# (change requires restart)
port 5433 # (change requires restart)更改密码
# 进入数据库已经设置了本地免密码可以直接进入sudo -u postgres psql# 修改密码
ALTER USER postgres WITH PASSWORD new_password;# 退出sql
\q查看postgres运行状态 rootlocalhost:/etc/postgresql/15/main# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMSLoaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)Active: active (exited) since Sun 2024-11-10 11:43:18 UTC; 38min agoProcess: 65703 ExecStart/bin/true (codeexited, status0/SUCCESS)Main PID: 65703 (codeexited, status0/SUCCESS)Nov 10 11:43:18 localhost.localdomain systemd[1]: Starting PostgreSQL RDBMS...
Nov 10 11:43:18 localhost.localdomain systemd[1]: Finished PostgreSQL RDBMS.重启数据库应该就可以远程连接了 systemctl restart postgresql3、安装postgis
安装 PostGIS
更新包列表
sudo apt update安装 PostGIS 对于 PostgreSQL 15您可以使用以下命令安装 PostGIS
sudo apt install postgresql-15-postgis-3
# 这里 postgis-3 是 PostGIS 的版本号确保与您的 PostgreSQL 版本兼容。验证安装
连接到 PostgreSQL 数据库
sudo -u postgres psql检查 PostGIS 扩展是否已安装
CREATE EXTENSION IF NOT EXISTS postgis;
# 如果 PostGIS 扩展已成功安装这个命令不会产生任何输出。验证 PostGIS 扩展是否已安装 运行以下查询以验证 PostGIS 扩展是否已安装
SELECT * FROM pg_available_extensions WHERE name postgis;
# 如果 PostGIS 扩展已安装您应该看到一些输出信息。检查当前数据库中的 PostGIS 函数 运行以下查询以检查当前数据库中的 PostGIS 函数
SELECT * FROM pg_proc WHERE proname LIKE addgeometrycolumn%;
# 如果 AddGeometryColumn 函数存在应该看到相关的信息。