目的:熟悉各種狀態下postgresql ,理解postgresql 服務運行步驟和基本原理
on linux centos 7
一、EDB 公司發行版 Interactive Installer postgresql-10.6-1-linux-x64.run
chmod +x postgresql-10.6-1-linux-x64.run
./postgresql-10.6-1-linux-x64.run
軟件目錄 /opt/PostgreSQL/10,數據目錄 /opt/PostgreSQL/10/data
/etc/systemd/system/multi-user.target.wants/postgresql-10.service 儲存的是連接
/usr/lib/systemd/system/postgresql-10.service 儲存的是文件
卸載不會刪除data文件目錄 和 postgres account
二 、rpm 版
通過yum
wget https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install pgdg-centos10-10-2.noarch.rpm
yum list |grep postgresql 選擇postgresql-10
但是 這個網站被牆了
於是手動下載rpm包
按順序安裝,有順序要求,如果順序錯了,按相應提示調整
postgresql-10.service存在
現在需要初始化數據庫
/usr/pgsql-10/bin/postgresql10-setup initdb
postgresql10-setip 本質上是調用 bin/initdb bin/intidb 是可以選擇pgdata目錄的
這種方式安裝的特點,自動創建了postgres 用戶
特定目錄,需要初始化數據庫,系統已經配置好了postgresql-10.service 啓動腳本;不需要手動啓動
安裝完後,需要設置密碼;
少了很多插件,需要手動安裝,比如plpython3u。
配置也需要空白,需要細心配置
數據庫服務,就是 軟件+數據庫目錄; 數據庫的安裝和運行,總的來說,就是下載軟件(bin),然後初始化數據目錄,最後寫一個服務腳本,添加到系統服務裏面去。
三、linux-binaries 版本
postgresql-10.6-1-linux-x64-binaries.tar.gz
tar -zxvf postgresql-10.6.1-linux-x64-binaries.tar.gz -C /opt/postgresql10
需要創建一個非root用戶
useradd -M postgres
服務的啓動需要postgres 對軟件目錄有權限
chown -R postgres /opt/postgresql10
mkdir /opt/postgresql10/data
su postgres
../bin/initdb -D /opt/postgresql10/data
pg_ctl -D /opt/postgresql10/data -l /opt/postgresql/data/startup.log start
四、源代碼版本
下載代碼https://www.postgresql.org/ftp/source/v10.6/
postgresql-10.6.tar.gz
tar -zxvf postgresql-10.6.tar.gz
cd postgresql-10.6
./configure --help 查看編譯選項
./configure --prefix=/opt/postgresql10 (缺什麼yum install ,可能有gcc zlib-devel readline-devel)
make && make install
(擴展的安裝 contrib cd contrib/pg_stat_statements/ make && make install 全部擴展 cd contrib/../ make world && make install-world )
創建用戶postgres
useradd postgres -M password xxxxxx
mkdir /opt/postgresql10/data
chown -R postgres:postgres /opt/postgresql10/data
/opt/postgresql10/bin/initdb -D /opt/postgresql10/data -E UTF8
啓動服務
/opt/postgresql10/bin/pg_ctl -D /opt/postgresql10/data -l /opt/postgresql10/data/startup.log start
改密碼
alter user postgres with password 'xxxxx';
改配置 postgresql.conf pg_hba.conf
/opt/postgresql10/bin/pg_ctl -D /opt/postgresql10/data -l /opt/postgresql10/data/startup.log restart
on windows
一、EDB postgresql
postgresql-10.5-1-windows-x64.exe
一鍵安裝
二、windows binaries (綠色版)
MSVCR120.dll 缺vc2013 安裝之
Visual Studio 6 : vc6
Visual Studio 2003 : vc7
Visual Studio 2005 : vc8
Visual Studio 2008 : vc9
Visual Studio 2010 : vc10
Visual Studio 2012 : vc11
Visual Studio 2013 : vc12
Visual Studio 2015 : vc14
Visual Studio 2017 : vc15
---------------------
bin\initdb -D C:\pgdata -U postgres -E UTF8 --locale=chs -W
bin\pg_ctl -D c:\pgdata -l c:\pgdata\startup.log start
註冊windows服務
bin\pg_ctl register -N postgresql10 -D c:\pgsql
刪除服務
bin\pg_ctl.exe unregister -N postgresql10
sc delete postgresql 10
net stop postgresql10
與 mysql的橫向對比
一、 rpm 包
MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar
rpm -e --no-deps mariadb-libs
rpm -ivh mysql-server
rmp -ivh mysql-client
rpm -ihv mysql-devel
改配置 /ect/my.cnf
systemctl start mysql
改密碼
set password=password('xxxxxx');
二 、binaries 安裝
yum install autoconf
rpm -e --nodeps mariadb-libs
tar -zxvf ... -C /opt
/etc/my.cnf
basedir=/opt/mysql
datadir=/opt/mysql/data
character-set-server=utf8
collation-server=utf8_general_ci
初始化數據庫
./bin/mysqld_safe --user=root &
改密碼
./bin/mysqladmin -uroot password xxxxx
登陸
./bin/mysql - u root -p
三、源代碼安裝