Monday, October 17, 2022

Yum or rpm based postgresql version 15 setup

Objective:

In this blog, we will see how we setup postgresql 15 using yum or rpm.

>>> Ensure the repository configuration file is updated to exclude the postgresql package from base and updates section to avoid later package incorrect resolutions

[root@10 ~]# ls -altr /etc/yum.repos.d/
total 56
-rw-r--r--.  1 root root  616 Nov 23  2020 CentOS-x86_64-kernel.repo
-rw-r--r--.  1 root root 8515 Nov 23  2020 CentOS-Vault.repo
-rw-r--r--.  1 root root 1331 Nov 23  2020 CentOS-Sources.repo
-rw-r--r--.  1 root root  630 Nov 23  2020 CentOS-Media.repo
-rw-r--r--.  1 root root  314 Nov 23  2020 CentOS-fasttrack.repo
-rw-r--r--.  1 root root  649 Nov 23  2020 CentOS-Debuginfo.repo
-rw-r--r--.  1 root root 1309 Nov 23  2020 CentOS-CR.repo
-rw-r--r--.  1 root root 1664 Nov 23  2020 CentOS-Base.repo
-rw-r--r--.  1 root root 1664 Oct 16 16:08 CentOS-Base.repo_bkp_16oct2022
drwxr-xr-x.  2 root root  258 Oct 16 16:08 .
drwxr-xr-x. 74 root root 8192 Oct 16 21:29 ..
[root@10 ~]# 

>>> Edit the CentOS-Base.repo

vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*

>>> Goto url
https://www.postgresql.org/download/linux/redhat/
Choose relevant options for the install. Copy the scripts supplied...... [Remember postgresql readme says the binary of the postgresql isnt owned by the postgres user as like oracle, where oracle owns the oracle rdbms binary]

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql15-server
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15


Command: yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Installed file:
-rw-r--r--.  1 root root 10693 Sep 29 19:52 pgdg-redhat-all.repo

I removed sudo, since I ran the commands as root user. Right now I dont have postgres user either, since the postgres user is needed only to own and manage postgres data not its binary

Command: yum install -y postgresql15-server
Failed due to 
...
Error: Package: postgresql15-15.0-1PGDG.rhel7.x86_64 (pgdg15)
           Requires: libzstd >= 1.4.0
Error: Package: postgresql15-server-15.0-1PGDG.rhel7.x86_64 (pgdg15)
           Requires: libzstd.so.1()(64bit)
Error: Package: postgresql15-15.0-1PGDG.rhel7.x86_64 (pgdg15)
           Requires: libzstd.so.1()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest


We need epel for this action:
yum -y install epel-release [which has the package libzstd]

yum install libzstd-devel

Install output:


[root@10 yum.repos.d]# yum install libzstd-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nxtgen.com
 * epel: download.nus.edu.sg
 * extras: mirrors.nxtgen.com
 * updates: mirrors.nxtgen.com
Resolving Dependencies
--> Running transaction check
---> Package libzstd-devel.x86_64 0:1.5.2-1.el7 will be installed
--> Processing Dependency: libzstd(x86-64) = 1.5.2-1.el7 for package: libzstd-devel-1.5.2-1.el7.x86_64
--> Processing Dependency: libzstd.so.1()(64bit) for package: libzstd-devel-1.5.2-1.el7.x86_64
--> Running transaction check
---> Package libzstd.x86_64 0:1.5.2-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
 Package                          Arch                      Version                         Repository               Size
==========================================================================================================================
Installing:
 libzstd-devel                    x86_64                    1.5.2-1.el7                     epel                     47 k
Installing for dependencies:
 libzstd                          x86_64                    1.5.2-1.el7                     epel                    282 k
Transaction Summary
==========================================================================================================================
Install  1 Package (+1 Dependent package)
Total download size: 330 k
Installed size: 918 k
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/libzstd-devel-1.5.2-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for libzstd-devel-1.5.2-1.el7.x86_64.rpm is not installed
(1/2): libzstd-devel-1.5.2-1.el7.x86_64.rpm                                                        |  47 kB  00:00:06
(2/2): libzstd-1.5.2-1.el7.x86_64.rpm                                                              | 282 kB  00:00:08
--------------------------------------------------------------------------------------------------------------------------
Total                                                                                      37 kB/s | 330 kB  00:00:08
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libzstd-1.5.2-1.el7.x86_64                                                                             1/2
  Installing : libzstd-devel-1.5.2-1.el7.x86_64                                                                       2/2
  Verifying  : libzstd-1.5.2-1.el7.x86_64                                                                             1/2
  Verifying  : libzstd-devel-1.5.2-1.el7.x86_64                                                                       2/2
Installed:
  libzstd-devel.x86_64 0:1.5.2-1.el7
Dependency Installed:
  libzstd.x86_64 0:1.5.2-1.el7
Complete!


[root@10 yum.repos.d]# ls -altr
total 80
-rw-r--r--.  1 root root  1050 Oct  2  2017 epel-testing.repo
-rw-r--r--.  1 root root   951 Oct  2  2017 epel.repo
-rw-r--r--.  1 root root   616 Nov 23  2020 CentOS-x86_64-kernel.repo
-rw-r--r--.  1 root root  8515 Nov 23  2020 CentOS-Vault.repo
-rw-r--r--.  1 root root  1331 Nov 23  2020 CentOS-Sources.repo
-rw-r--r--.  1 root root   630 Nov 23  2020 CentOS-Media.repo
-rw-r--r--.  1 root root   314 Nov 23  2020 CentOS-fasttrack.repo
-rw-r--r--.  1 root root   649 Nov 23  2020 CentOS-Debuginfo.repo
-rw-r--r--.  1 root root  1309 Nov 23  2020 CentOS-CR.repo
-rw-r--r--.  1 root root 10693 Sep 29 19:52 pgdg-redhat-all.repo-new
-rw-r--r--.  1 root root  1664 Oct 16 16:08 CentOS-Base.repo_bkp_16oct2022
-rw-r--r--.  1 root root  1706 Oct 16 22:35 CentOS-Base.repo
drwxr-xr-x.  2 root root  4096 Oct 16 22:35 .
drwxr-xr-x. 74 root root  8192 Oct 16 22:39 ..

[root@10 yum.repos.d]# mv pgdg-redhat-all.repo-new pgdg-redhat-all.repo

postgresql 15 install:

[root@10 yum.repos.d]# yum install -y postgresql15-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: download.nus.edu.sg
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package postgresql15-server.x86_64 0:15.0-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql15-libs(x86-64) = 15.0-1PGDG.rhel7 for package: postgresql15-server-15.0-1PGDG.rhel7.x86_64
--> Processing Dependency: postgresql15(x86-64) = 15.0-1PGDG.rhel7 for package: postgresql15-server-15.0-1PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql15-server-15.0-1PGDG.rhel7.x86_64
--> Processing Dependency: libicuuc.so.50()(64bit) for package: postgresql15-server-15.0-1PGDG.rhel7.x86_64
--> Processing Dependency: libicui18n.so.50()(64bit) for package: postgresql15-server-15.0-1PGDG.rhel7.x86_64
--> Running transaction check
---> Package libicu.x86_64 0:50.2-4.el7_7 will be installed
---> Package postgresql15.x86_64 0:15.0-1PGDG.rhel7 will be installed
---> Package postgresql15-libs.x86_64 0:15.0-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
 Package                             Arch                   Version                          Repository              Size
==========================================================================================================================
Installing:
 postgresql15-server                 x86_64                 15.0-1PGDG.rhel7                 pgdg15                 5.6 M
Installing for dependencies:
 libicu                              x86_64                 50.2-4.el7_7                     base                   6.9 M
 postgresql15                        x86_64                 15.0-1PGDG.rhel7                 pgdg15                 1.5 M
 postgresql15-libs                   x86_64                 15.0-1PGDG.rhel7                 pgdg15                 277 k
Transaction Summary
==========================================================================================================================
Install  1 Package (+3 Dependent packages)
Total download size: 14 M
Installed size: 55 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/pgdg15/packages/postgresql15-libs-15.0-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Public key for postgresql15-libs-15.0-1PGDG.rhel7.x86_64.rpm is not installed
(1/4): postgresql15-libs-15.0-1PGDG.rhel7.x86_64.rpm                                               | 277 kB  00:00:10
(2/4): libicu-50.2-4.el7_7.x86_64.rpm                                                              | 6.9 MB  00:00:27
(3/4): postgresql15-15.0-1PGDG.rhel7.x86_64.rpm                                                    | 1.5 MB  00:00:29
(4/4): postgresql15-server-15.0-1PGDG.rhel7.x86_64.rpm                                             | 5.6 MB  00:00:40
--------------------------------------------------------------------------------------------------------------------------
Total                                                                                     286 kB/s |  14 MB  00:00:51
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
 Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
 Package    : pgdg-redhat-repo-42.0-27.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql15-libs-15.0-1PGDG.rhel7.x86_64                                                              1/4
  Installing : libicu-50.2-4.el7_7.x86_64                                                                             2/4
  Installing : postgresql15-15.0-1PGDG.rhel7.x86_64                                                                   3/4
  Installing : postgresql15-server-15.0-1PGDG.rhel7.x86_64                                                            4/4
  Verifying  : postgresql15-server-15.0-1PGDG.rhel7.x86_64                                                            1/4
  Verifying  : libicu-50.2-4.el7_7.x86_64                                                                             2/4
  Verifying  : postgresql15-libs-15.0-1PGDG.rhel7.x86_64                                                              3/4
  Verifying  : postgresql15-15.0-1PGDG.rhel7.x86_64                                                                   4/4
Installed:
  postgresql15-server.x86_64 0:15.0-1PGDG.rhel7
Dependency Installed:
  libicu.x86_64 0:50.2-4.el7_7    postgresql15.x86_64 0:15.0-1PGDG.rhel7    postgresql15-libs.x86_64 0:15.0-1PGDG.rhel7
Complete!
[root@10 yum.repos.d]#

>>> user and group postgres is by default added in the course...

[root@10 yum.repos.d]# groupadd postgres
groupadd: group 'postgres' already exists

[root@10 yum.repos.d]# id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres)
[root@10 yum.repos.d]#

>>> Initalizing the data directory:

Ex.:
root# mkdir /usr/local/pgsql
root# chown postgres /usr/local/pgsql
root# su postgres
postgres$ initdb -D /usr/local/pgsql/data

Actual: <<< we use the data directory we seperately created.
mkdir /pgDATA/data
[root@10 yum.repos.d]# chown postgres:postgres /pgDATA/data
[root@10 yum.repos.d]# ls -ld /pgDATA/data
drwxr-xr-x. 2 postgres postgres 6 Oct 16 22:59 /pgDATA/data
[root@10 yum.repos.d]#

>>> Update the .bash_profile of postgres user:

-bash-4.2$ cat .bash_profile
[ -f /etc/profile ] && source /etc/profile
PGDATA=/pgDATA/data  << appended
export PGDATA
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile
export PATH=$PATH:/usr/pgsql-15/bin:/usr/pgsql-15/lib:  <<< appended
-bash-4.2$

>>> logged in as postgres user and initialized the db

initdb -D /pgDATA/data

-bash-4.2$ echo $PGDATA
/pgDATA/data

-bash-4.2$ initdb -D $PGDATA
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /pgDATA/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /pgDATA/data -l logfile start

-bash-4.2$

The cluster database is initialized.

No comments:

Post a Comment

Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...