Postgresql 12 是有很多新增特性的,但是最關鍵的一點是Postgresql 12 的SQL備份文件是不能直接使用psql命令導入到Postgresql 10 的。
Ubuntu18.04 默認的安裝方式 apt install postgresql 安裝的是 postgresql 10,這就導致了數據庫恢復的時候會出現一些麻煩。
可以先移除已經安裝的 pg10
sudo apt-get --purge remove postgresql*
建議先期增加阿里源 避免 下載不到 其他的依賴的包
mv /etc/apt/sources.list cat << EOF >/etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse EOF
所以,最好選擇一步到位安裝postgresql 12.
Ubuntu 20.04 上面使用 apt install postgresql 默認安裝的就是Postgresql 12 了。ubuntu18.04 需要進行部分處理.
安裝命令 # 添加 Postgresql 源到系統源 sudo 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 | sudo apt-key add - # 更新軟件包列表 # 在此之前可以先將軟件源更換為國內的軟件源 sudo apt-get update # 安裝最新版本的 PostgreSQL # 如果想要指定版本的話,使用 postgresql-12 sudo apt-get install postgresql-12 postgresql-contrib
# 注意需要安裝這個contrib 才可以使用 uuid 等函數.
注意查看服務信息
systemctl |grep postgres
發現 ubuntu與centos的服務名不太一樣
可以查看 postgresql@12-main 的服務 修改配置文件 並且設置開機啟動等.
有一點比較好的是 不需要想rpm安裝時 還需要進行一次 initdb的操作
注意設置開機啟動的命令也比較簡單:
systemctl enable postgresql@12-main
即可.
修改數據庫的字符集
注意 默認安裝的是 latin1 的字符集 可能不符合產品的需求 需要進行處理 root 用戶下 systemctl stop postgresql@12-main rm -rf /var/lib/postgresql/12/main/* su - postgres 重建數據庫 cd /usr/lib/postgresql/12/bin export LANG=en_US.UTF-8 ./initdb -D /var/lib/postgresql/12/main -E UTF8 然后重啟數據庫 systemctl restart postgresql@12-main 注意需要修改 pg_hba.conf 以及 postgresql.conf 的配置文件. 建議 localhost 可以trust 訪問. 其他ip地址 至少 md5訪問 修改管理員密碼 su - postgres psql alter user postgres with password 'Test20131127' ;
部分學習自:
https://blog.csdn.net/qq_36963372/article/details/107658420