Monday, January 29, 2024

pgbadger session - 2 : PostgreSQL configuration for pgbadger

 

PostgreSQL config to bring forward much benefits out of pgbadger:


A. pg_setting - we need to have at minimum for pgbadger to work flawlessly or effectively:


1. log_min_duration_statement = 0 [increase the value if needed, this value creates additional stress to a loaded machine]

2. for stderr (default)

log_line_prefix = '%t [%p]: db=%d,user=%u,app=%a,client=%h '

3. Other options to enable:

        log_checkpoints = on

        log_connections = on

        log_disconnections = on

        log_lock_waits = on

        log_temp_files = 0

        log_autovacuum_min_duration = 0

        log_error_verbosity = default

4. Ensure english is the language for log messages


        lc_messages='en_US.UTF-8'

        lc_messages='C'


5. Recommendation: Do not enable both log_min_duration_statement, log_duration and log_statement all together


log_min_duration_statement --- number of ms over which the queries shouldbe reported

log_duration --- set to log_min_duration_statement set to -1 and log_duration set


or


log_statement =all (no setting for other 2)


B. Verify pg_setting shows the new values were set properly


select name,setting

from pg_settings

where name in ('log_destination'

, 'log_min_duration_statement'

, 'log_line_prefix'

, 'log_checkpoints'

, 'log_connections'

, 'log_disconnections'

, 'log_lock_waits'

, 'log_temp_files'

, 'log_autovacuum_min_duration'

, 'log_error_verbosity'

, 'lc_messages'

)

order by 1;


alter system set log_min_duration_statement = 0;

alter system set log_line_prefix = '%t [%p]: db=%d,user=%u,app=%a,client=%h ';

alter system set log_checkpoints = on;

alter system set log_connections = on;

alter system set log_disconnections = on;

alter system set log_lock_waits = on;

alter system set log_temp_files = 0;

alter system set log_autovacuum_min_duration = 0;


select pg_reload_conf();



select name,setting

from pg_settings

where name in ('log_destination'

, 'log_min_duration_statement'

, 'log_line_prefix'

, 'log_checkpoints'

, 'log_connections'

, 'log_disconnections'

, 'log_lock_waits'

, 'log_temp_files'

, 'log_autovacuum_min_duration'

, 'log_error_verbosity'

, 'lc_messages'

)

order by 1;


-- We will need to take a postgresql bounce, since the log_connections and log_disconnections wont reflect with pg_reload_conf().


Target value:


            name             |                 setting

-----------------------------+------------------------------------------

 lc_messages                 | en_US.UTF-8

 log_autovacuum_min_duration | 0

 log_checkpoints             | on

 log_connections             | on

 log_destination             | stderr

 log_disconnections          | on

 log_error_verbosity         | default

 log_line_prefix             | %t [%p]: db=%d,user=%u,app=%a,client=%h

 log_lock_waits              | on

 log_min_duration_statement  | 0

 log_temp_files              | 0

(11 rows)


postgres=#


YouTube Video:


pgbadger session 1 - installation of pgbadger

 Steps to install pgbadger


From pgBadger documentation: https://pgbadger.darold.net/documentation.html


1. Download the pgbadger from github


url: https://github.com/darold/pgbadger


2. Install using the below step


        tar xzf pgbadger-11.x.tar.gz

        cd pgbadger-11.x/

        perl Makefile.PL

        make && sudo make install


Instead I followed the below steps instead of 1 & 2:

mkdir pgbadger

git clone https://github.com/darold/pgbadger.git pgbadger

perl Makefile.PL

make && sudo make install



-bash-4.2$ git clone https://github.com/darold/pgbadger.git pgbadger

Cloning into 'pgbadger'...

remote: Enumerating objects: 5038, done.

remote: Counting objects: 100% (726/726), done.

remote: Compressing objects: 100% (297/297), done.

remote: Total 5038 (delta 458), reused 541 (delta 403), pack-reused 4312

Receiving objects: 100% (5038/5038), 12.47 MiB | 13.21 MiB/s, done.

Resolving deltas: 100% (3122/3122), done.

-bash-4.2$



-bash-4.2$ perl Makefile.PL

Checking if your kit is complete...

Looks good

Writing Makefile for pgBadger

-bash-4.2$


As root:


[root@vcentos79-postgres-ha1 pgbadger]# make && sudo make install

which: no pod2markdown in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

Makefile:824: You must install pod2markdown to generate README.md from doc/pgBadger.pod

echo "=head1 SYNOPSIS" > doc/synopsis.pod

./pgbadger --help >> doc/synopsis.pod

echo "=head1 DESCRIPTION" >> doc/synopsis.pod

sed -i.bak 's/ +$//g' doc/synopsis.pod

rm doc/synopsis.pod.bak

sed -i.bak '/^=head1 SYNOPSIS/,/^=head1 DESCRIPTION/d' doc/pgBadger.pod

sed -i.bak '4r doc/synopsis.pod' doc/pgBadger.pod

rm doc/pgBadger.pod.bak

Manifying blib/man1/pgbadger.1p

rm doc/synopsis.pod

which: no pod2markdown in (/sbin:/bin:/usr/sbin:/usr/bin)

Makefile:824: You must install pod2markdown to generate README.md from doc/pgBadger.pod

echo "=head1 SYNOPSIS" > doc/synopsis.pod

./pgbadger --help >> doc/synopsis.pod

echo "=head1 DESCRIPTION" >> doc/synopsis.pod

sed -i.bak 's/ +$//g' doc/synopsis.pod

rm doc/synopsis.pod.bak

sed -i.bak '/^=head1 SYNOPSIS/,/^=head1 DESCRIPTION/d' doc/pgBadger.pod

sed -i.bak '4r doc/synopsis.pod' doc/pgBadger.pod

rm doc/pgBadger.pod.bak

Manifying blib/man1/pgbadger.1p

Installing /usr/local/share/man/man1/pgbadger.1p

Installing /usr/local/bin/pgbadger

Appending installation info to /usr/lib64/perl5/perllocal.pod

rm doc/synopsis.pod

[root@vcentos79-postgres-ha1 pgbadger]# echo $?

0

[root@vcentos79-postgres-ha1 pgbadger]#




Error#1:

-bash-4.2$ perl Makefile.PL

Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.

BEGIN failed--compilation aborted at Makefile.PL line 1.



Resolution:

yum install perl-devel


...


Transaction test succeeded

Running transaction

  Installing : gdbm-devel-1.10-8.el7.x86_64                                                                                                                             1/10

  Installing : pyparsing-1.5.6-9.el7.noarch                                                                                                                             2/10

  Installing : systemtap-sdt-devel-4.0-13.el7.x86_64                                                                                                                    3/10

  Installing : perl-ExtUtils-Manifest-1.61-244.el7.noarch                                                                                                               4/10

  Installing : perl-Test-Harness-3.28-3.el7.noarch                                                                                                                      5/10

  Installing : libdb-devel-5.3.21-25.el7.x86_64                                                                                                                         6/10

  Installing : perl-ExtUtils-MakeMaker-6.68-3.el7.noarch                                                                                                                7/10

  Installing : perl-ExtUtils-Install-1.58-299.el7_9.noarch                                                                                                              8/10

  Installing : 4:perl-devel-5.16.3-299.el7_9.x86_64                                                                                                                     9/10

  Installing : 1:perl-ExtUtils-ParseXS-3.18-3.el7.noarch                                                                                                               10/10

  Verifying  : 1:perl-ExtUtils-ParseXS-3.18-3.el7.noarch                                                                                                                1/10

  Verifying  : libdb-devel-5.3.21-25.el7.x86_64                                                                                                                         2/10

  Verifying  : perl-Test-Harness-3.28-3.el7.noarch                                                                                                                      3/10

  Verifying  : perl-ExtUtils-Install-1.58-299.el7_9.noarch                                                                                                              4/10

  Verifying  : perl-ExtUtils-Manifest-1.61-244.el7.noarch                                                                                                               5/10

  Verifying  : systemtap-sdt-devel-4.0-13.el7.x86_64                                                                                                                    6/10

  Verifying  : pyparsing-1.5.6-9.el7.noarch                                                                                                                             7/10

  Verifying  : gdbm-devel-1.10-8.el7.x86_64                                                                                                                             8/10

  Verifying  : perl-ExtUtils-MakeMaker-6.68-3.el7.noarch                                                                                                                9/10

  Verifying  : 4:perl-devel-5.16.3-299.el7_9.x86_64                                                                                                                    10/10


Installed:

  perl-devel.x86_64 4:5.16.3-299.el7_9


Dependency Installed:

  gdbm-devel.x86_64 0:1.10-8.el7                          libdb-devel.x86_64 0:5.3.21-25.el7                       perl-ExtUtils-Install.noarch 0:1.58-299.el7_9

  perl-ExtUtils-MakeMaker.noarch 0:6.68-3.el7             perl-ExtUtils-Manifest.noarch 0:1.61-244.el7             perl-ExtUtils-ParseXS.noarch 1:3.18-3.el7

  perl-Test-Harness.noarch 0:3.28-3.el7                   pyparsing.noarch 0:1.5.6-9.el7                           systemtap-sdt-devel.x86_64 0:4.0-13.el7


Complete!


Error#2:


-bash-4.2$ make && sudo make install

which: no pod2markdown in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/pgsql-15/bin:/usr/pgsql-15/lib)

Makefile:824: You must install pod2markdown to generate README.md from doc/pgBadger.pod

cp pgbadger blib/script/pgbadger

/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/pgbadger

echo "=head1 SYNOPSIS" > doc/synopsis.pod

./pgbadger --help >> doc/synopsis.pod

echo "=head1 DESCRIPTION" >> doc/synopsis.pod

sed -i.bak 's/ +$//g' doc/synopsis.pod

rm doc/synopsis.pod.bak

sed -i.bak '/^=head1 SYNOPSIS/,/^=head1 DESCRIPTION/d' doc/pgBadger.pod

sed -i.bak '4r doc/synopsis.pod' doc/pgBadger.pod

rm doc/pgBadger.pod.bak

Manifying blib/man1/pgbadger.1p

rm doc/synopsis.pod


We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:


    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.


[sudo] password for postgres:

postgres is not in the sudoers file.  This incident will be reported.

-bash-4.2$


Fix: Run the same command as root


[root@vcentos79-postgres-ha1 pgbadger]# make && sudo make install

which: no pod2markdown in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

Makefile:824: You must install pod2markdown to generate README.md from doc/pgBadger.pod

echo "=head1 SYNOPSIS" > doc/synopsis.pod

./pgbadger --help >> doc/synopsis.pod

echo "=head1 DESCRIPTION" >> doc/synopsis.pod

sed -i.bak 's/ +$//g' doc/synopsis.pod

rm doc/synopsis.pod.bak

sed -i.bak '/^=head1 SYNOPSIS/,/^=head1 DESCRIPTION/d' doc/pgBadger.pod

sed -i.bak '4r doc/synopsis.pod' doc/pgBadger.pod

rm doc/pgBadger.pod.bak

Manifying blib/man1/pgbadger.1p

rm doc/synopsis.pod

which: no pod2markdown in (/sbin:/bin:/usr/sbin:/usr/bin)

Makefile:824: You must install pod2markdown to generate README.md from doc/pgBadger.pod

echo "=head1 SYNOPSIS" > doc/synopsis.pod

./pgbadger --help >> doc/synopsis.pod

echo "=head1 DESCRIPTION" >> doc/synopsis.pod

sed -i.bak 's/ +$//g' doc/synopsis.pod

rm doc/synopsis.pod.bak

sed -i.bak '/^=head1 SYNOPSIS/,/^=head1 DESCRIPTION/d' doc/pgBadger.pod

sed -i.bak '4r doc/synopsis.pod' doc/pgBadger.pod

rm doc/pgBadger.pod.bak

Manifying blib/man1/pgbadger.1p

Installing /usr/local/share/man/man1/pgbadger.1p

Installing /usr/local/bin/pgbadger

Appending installation info to /usr/lib64/perl5/perllocal.pod

rm doc/synopsis.pod

[root@vcentos79-postgres-ha1 pgbadger]# echo $?

0

[root@vcentos79-postgres-ha1 pgbadger]#



3. Verify if the pgbadger file is accessible, if so from where


-bash-4.2$ which pgbadger

/usr/local/bin/pgbadger

-bash-4.2$ ls -altr /usr/local/share/man/man1/

total 48

drwxr-xr-x. 21 root root   243 Mar 19  2023 ..

-r--r--r--.  1 root root 45127 Jan 28 06:38 pgbadger.1p

drwxr-xr-x.  2 root root    25 Jan 28 06:38 .


-bash-4.2$ pgbadger --help


Usage: pgbadger [options] logfile [...]


    PostgreSQL log analyzer with fully detailed reports and graphs.


Arguments:

..



YouTube video:


Saturday, January 27, 2024

Oracle Full (not level 0) and incremental backup - how they support each other

 Dears,

This last week,  I was asked to perform a backup and restore exercise.

This is completely a new db, not in my support scope.

Still did study the DB setup thoroughly and gave feedbacks and brought as much as inputs as I needed.

There was a immense pressure on me to execute this adhoc backup/restore exercise for the db successfully due to some so and so reasons, which I cant discuss.

Anyway, challenge upfront - step into an unknown waters (the customizations), but it is still it is oracle DB.  The study I did , helped me to gain sufficient knowledge to carve out the plan for the restore/recovery exercise.


Objective: Refresh DEV with PROD data. The DB size was 14TB. This needs to be executed in a reasonable time frame. Last time the activity happened on Oct 2023, but no disclosure of the plan, but the only info given was restore took 7hrs.


I prepared the plan, and executed all prereqs, that night I was shared the credentials to login to the target DB where the restore is to be done.

On the 'D' day, I learnt the backups which are secured on the weekends "FULL" backup not incremental backup. Rest all days the backup admin is securing incremenal level 1.


So a FULL on sunday and all other days are an incremental level 1.

I was just blown away by this config, this is a managed backup, so no backup logs accessible before. My fault I didnt scrutinize the backup before. I kept hearing there is a incremental level 0 and level 1 but there is a mistake -- hrrrrrrrrr!


Ok, now the challenege ahead with 3TB worth of archive to recover from Full backup the PITR requested.

So I proceeded with the restore...

Attempt  1 - restore  failed due to the "convert" strings in init param not supporting non-omf db restore.

Attempt  2 - Set new name for the datafiles by dynamically generating string using regexp_replace(name,'source','tgt',1,1) from v$datafile view and set them up in the restore command.


run

{

set newname for datafile 1 to '/tgt/file1.dbf';

set until time to_date('');

restore database;

}

while the restore was ongoing I broke the archive restore command into 9 parts thinking I have to

>> restore archives

>> recover archives

>>purge archives

This is when my stuck an option where rman already automated this routine...

recover database delete archivelog XXX G;

This does all what was mentioned above.


Restore finished in 3hrs for 11TB.

Now comes the main discussion point of this blog, when I kicked this recovery on.

To my surprise, the incremental level 1 was used and it was used properly; which made me wonder what could have happened?

I didn't collect evidence, but I will when I find opportunity..


1. Full backup doesn't store the incremental scn value in the dictionary which is its nature.  So my assumption was they don't participate in incremental restore & recovery

This is where oracle turned smart, oracle after full backup was restored.

 The incremental level 1 backup it used was actually taken on top of the last incremental level 1.So ideally what happened is,


Full backup restored df1 (scn-111), df2 (scn-123) etc..

incremental level 1 had changes captured from 99 and hence this incremental level 1 was used during this recovery exercise successfully. The archives left over were used as required to roll forward the DB.


Thanks



Thursday, January 11, 2024

Oracle RDBMS 11.2 - Service Setup - HA config

 Dears,

Today while I was running through a Operation Acceptance Testing (OAT) in my DB.

My DB version 11.2 (but it applies to all DB version until atleast 19c) running without SIHA or GI.

The objective of the OAT was to test the application connection during db switchover.

Mistake # 1 - we never created the HA TNS for this DB

Mistake # 2 - we didnt setup dataguard broker on this DB


Mistake#2 - I already prepared a SOP, I ran through it and it was ALL OK. Note I faced ORA-16664 & ORA-16665 errors when I enabled the configuration. Fix was to properly setup local_listener setting, since the <DBUNIQUENAME>_DGB service wasnt starting up, until the local_listener is properly setup in a listener with non default port or listener name different from "LISTENER".

So the DGMGRL is all OK.


I stumbled with my (team) mistake, which is service miss. I never have setup a service on a standalone DB with no SIHA. 

I used to run

srvctl add service...

But now I dont want to just setup the below as well, since I wanted this service to be available across both primary and standby.

alter system set service_name='XXXXXX'; -- some service name

Then threw google search & OTN I learnt, 

exec dbms_service.create_service( -

service_name=>''

,network_name=>''

,...

);

can be used to setup the service.

On top of it, we need to setup a DB startup trigger which kicks off the service when the database_role matches "PRIMARY".

So this saved my day.

I proceeded to change the description part  (to include new service name) of the app TNS, since I cant change the alias now, which is used everywhere in app.

I started around 11:00AM to prepare for the OAT, finished all the setup by 2PM

Good news is the OAT finished fine. The switchover, switchback ALL went just fine.


Thanks

Wednesday, January 10, 2024

Query to check rman backup details in oracle

Query to check rman backup details in oracle:


set lines 220
set pages 1000
col cf for 9,999
col df for 9,999
col elapsed_seconds heading "ELAPSED|SECONDS"
col i0 for 9,999
col i1 for 9,999
col l for 9,999
col output_mbytes for 999,999,999 heading "OUTPUT|MBYTES"
col session_recid for 999999 heading "SESSION|RECID"
col session_stamp for 99999999999 heading "SESSION|STAMP"
col status for a10 trunc
col time_taken_display for a10 heading "TIME|TAKEN"
col output_instance for 9999 heading "OUT|INST"
select
  j.session_recid, j.session_stamp,
  to_char(j.start_time, 'yyyy-mm-dd hh24:mi:ss') start_time,
  to_char(j.end_time, 'yyyy-mm-dd hh24:mi:ss') end_time,
  (j.output_bytes/1024/1024) output_mbytes, j.status, j.input_type,
  decode(to_char(j.start_time, 'd'), 1, 'Sunday', 2, 'Monday',
                                     3, 'Tuesday', 4, 'Wednesday',
                                     5, 'Thursday', 6, 'Friday',
                                     7, 'Saturday') dow,
  j.elapsed_seconds, j.time_taken_display,
  x.cf, x.df, x.i0, x.i1, x.l,
  ro.inst_id output_instance
from V$RMAN_BACKUP_JOB_DETAILS j
  left outer join (select
                     d.session_recid, d.session_stamp,
                     sum(case when d.controlfile_included = 'YES' then d.pieces else 0 end) CF,
                     sum(case when d.controlfile_included = 'NO'
                               and d.backup_type||d.incremental_level = 'D' then d.pieces else 0 end) DF,
                     sum(case when d.backup_type||d.incremental_level in ('I0', 'D0') then d.pieces else 0 end) I0,
                     sum(case when d.backup_type||d.incremental_level = 'I1' then d.pieces else 0 end) I1,
                     sum(case when d.backup_type = 'L' then d.pieces else 0 end) L
                   from
                     V$BACKUP_SET_DETAILS d
                     join V$BACKUP_SET s on s.set_stamp = d.set_stamp and s.set_count = d.set_count
                   where s.input_file_scan_only = 'NO'
                   group by d.session_recid, d.session_stamp) x
    on x.session_recid = j.session_recid and x.session_stamp = j.session_stamp
  left outer join (select o.session_recid, o.session_stamp, min(inst_id) inst_id
                   from GV$RMAN_OUTPUT o
                   group by o.session_recid, o.session_stamp)
    ro on ro.session_recid = j.session_recid and ro.session_stamp = j.session_stamp
where j.start_time > trunc(sysdate)-&NUMBER_OF_DAYS
order by j.start_time;

>> on the prompt enter the # of days you want the backup for.

This is controlled by below setting in rman:

Configure RMAN output to keep for 'n' days;

where n is the number of days the information is retained.

This is a quick query sharing blog.

Thanks

OKV platform certificate rotation - pitfall , awareness!!!!

OKV version: 21.9 Setup: Multimaster R/W cluster Plan: https://docs.google.com/spreadsheets/d/e/2PACX-1vSaXXTjj9cE1fvYpNmsDNBOkTIw78yTwQ6a9o...