ติดตั้ง postgresql จาก source
เมื่อวันที่ 1 มีนาคม 2018 ที่ผ่านมา postgresql ได้ประกาศ release postgresql 10.3 ลองมาทดสอบการใช้งานโดยการติดตั้งผ่าน Source กันดู
1 2 3 4 5 6 7 8 9 10 11 |
$ sudo su - # dnf install gcc zlib-devel readline-devel # cd /opt # wget https://ftp.postgresql.org/pub/source/v10.3/postgresql-10.3.tar.gz # tar xvf postgresql-10.3.tar.gz # cd postgresql-10.3 # ./configure --prefix=/opt/postgresql-10.3 # make # make install # ls /opt/postgresql-10.3/bin |
สร้าง user สำหรับใช้งาน เนื่องจากเราทำงานใน ฐานะของ root และ ก่อนการใช้งานจะต้องสร้าง user ชื่อ postgres แทน root
1 2 3 4 5 6 7 8 |
# useradd postgres # passwd postgres # mkdir -p /pgdatabase/data # chown -R postgres. /pgdatabase/data # ls -ld /pgdatabase/data drwxr-xr-x 2 postgres postgres 4096 Apr 8 21:02 /pgdatabase/data # echo 'export PATH=$PATH:/opt/postgresql-10.3/bin' > /etc/profile.d/postgres.sh |
ขั้นตอน initial Database โดยให้เปลี่ยนเป็น user postgres
1 2 3 4 5 6 |
# su - postgres [postgres@localhost~]$ initdb -D /pgdatabase/data/ -U postgres -W ... Success. You can now start the database server using: pg_ctl -D /pgdatabase/data/ -l logfile start |
รายละเดียด -D ที่เก็บ Database -U Database Super user -W หยุดถาม password เริ่มต้น start ด้วยคำสั่ง pg_ctl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ pg_ctl -D /pgdatabase/data/ -l logfile start waiting for server to start.... done server started [postgres@itbakery ~]$ psql -U postgres psql (10.3) Type "help" for help. postgres=# alter role postgres with password 'postgres'; <--set password ALTER ROLE postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows) postgres=# \q $ pg_ctl -D /pgdatabase/data/ -l logfile stop waiting for server to shut down.... done server stopped |
ปรับแต่ง config
1 2 3 |
cd /pgdatabase/data/ ... postgresql.conf pg_hba.conf |
…