Connecting to PostgreSQL

To connect to PostgreSQL, the following parameters are required:

1. Host or Host Address
2. Port
3. Database Name
4. User
5. Password

As mentioned, in my earlier post, like sqlplus in oracle, PostgreSQL has “psql”.
To connect any PostgreSQL db, you can use

1. psql
2. pgAdmin4
3. phpPgAdmin

Using psql

The default port number for PostgreSQL is 5432.

i) psql -h hostname -p port -d dbname -U username

bash-3.2$ psql -h localhost -p 5432 -d postgres -U anand
psql (9.6.1)
Type "help" for help.

postgres=#


ii) bash-3.2$ psql postgres
psql (9.6.1)
Type "help" for help.

postgres=#
postgres=# select current_user;
 current_user
--------------
 anand
(1 row)


iii) URI format

bash-3.2$ psql postgresql://localhost:5432/postgres
psql (9.6.1)
Type "help" for help.

postgres=#
postgres=# select current_database();
 current_database
------------------
 postgres
(1 row)

postgres=# select inet_server_addr(), inet_server_port();
 inet_server_addr | inet_server_port
------------------+------------------
 ::1              |             5432
(1 row)

postgres=# select version();
                                                    version
----------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.6.1 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.42.1), 64-bit
(1 row)

postgres=#
postgres=# \conninfo
You are connected to database "postgres" as user "anand" on host "localhost" at port "5432".
postgres=#

PgAdmin4 and phpPgAdmin are Graphical Administrations tools. For more details

https://www.pgadmin.org/

Please note, when connecting with PgAdmin you should uncheck the “Strore Password” box.

A password file contains 5 fields

host:port:dbname:user:password

The password file is located using an env variable PGPASSFILE. If its not set, then default filename and locationfor *nix system is ~/.pgpass. Make sure the file permission is 0600.

ls -lrt /Users/anand/.pgpass

In case the file is present, and you try to connect using psql, it won’t prompt for password.

To check connection status of PostgreSQL server, use pg_isready

bash-3.2$ pg_isready -h localhost -p 5433
localhost:5433 - no response
bash-3.2$ pg_isready -h localhost -p 5432
localhost:5432 - accepting connections
bash-3.2$

Next, I will writing on exploring the PostgreSQL db.

Advertisements

PostgreSQL – An introduction

2017 – A year of learning !!

Today technology is changing at a very rapid speed and it’s very difficult to keep up to it but as said, it’s never too late to start something new. This year I plan to spend some time outside of Oracle and learn some new things.

I have started learning PostgreSQL and I want to take this platform to share my learning and to learn from others.  As this is the start, it would very basic and hopefully with time, I will share more interesting things.

So, without wasting any more time, lets get started.

This blog is about PostgreSQL installation on MAC and a little more.

As HomeBrew is already running on my mac, I will use “Brew” to install PostgreSQL.

HomeBrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system.

You can read more about it on —

https://en.wikipedia.org/wiki/Homebrew_(package_management_software)

http://brew.sh/

Brew Installation is very simple.


bash-3.2$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Once installed, PostgreSQL installation is just one line command :-


bash-3.2$ brew --version
Homebrew 1.1.8
Homebrew/homebrew-core (git revision 3605; last commit 2017-01-23)
bash-3.2$
bash-3.2$
bash-3.2$ brew install postgres
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-9.6.1.el_capitan.bottle.tar.gz
==> Using the sandbox
==> /usr/local/Cellar/postgresql/9.6.1/bin/initdb /usr/local/var/postgres
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see:
https://www.postgresql.org/docs/9.6/static/upgrading.html

To migrate existing data from a previous minor version (9.0-9.5) of PostgreSQL, see:
https://www.postgresql.org/docs/9.6/static/pgupgrade.html

You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.
Do not run `brew cleanup postgresql` until you have performed the migration.

To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
==> Summary
🍺  /usr/local/Cellar/postgresql/9.6.1: 3,242 files, 36.4M
bash-3.2$

 Now, to start the PostgreSQL services

bash-3.2$ brew services start postgresql
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 10 (delta 0), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
Tapped 0 formulae (37 files, 50.7K)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
bash-3.2$
bash-3.2$ ps -ef | grep postgres
1463626507 35179     1   0  7:38AM ??         0:00.03 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres
1463626507 35182 35179   0  7:38AM ??         0:00.00 postgres: checkpointer process
1463626507 35183 35179   0  7:38AM ??         0:00.01 postgres: writer process
1463626507 35184 35179   0  7:38AM ??         0:00.00 postgres: wal writer process
1463626507 35185 35179   0  7:38AM ??         0:00.00 postgres: autovacuum launcher process
1463626507 35186 35179   0  7:38AM ??         0:00.00 postgres: stats collector process
1463626507 35191 26530   0  7:38AM ttys004    0:00.00 grep postgres
bash-3.2$
bash-3.2$ postgres --version
postgres (PostgreSQL) 9.6.1

Few things to note here :-

1. The postgresql services can be stoped/started either using “brew services” or pg_ctl utility. “Brew services” will only be avaliable in case you have installed homebrew.

2. /usr/local/var/postgres –> Is the data directory. The location can be different depending on the OS. It contains configuration file, pid detail file, tablespaces and other details. I will post more on this in another blog.

3. The PID of the postgres process can be found using the ps program, or from the file postmaster.pid in the data directory.

4. PostgreSQL postmaster is the master server process. postmaster is a deprecated alias of postgres.

bash-3.2$ cd /usr/local/var/postgres
bash-3.2$ cat postmaster.pid
59448   -->  PID 
/usr/local/var/postgres  --> Data Directory 
1485658006
5432  --> Port
/tmp --> Unix socket
localhost
  5432001   1310723

postgres=# \conninfo
You are connected to database "postgres" as user "prakanan" via socket in "/tmp" at port "5432".

5. After the service is up and running, you can connect to the database using psql, similar to sqlplus in Oracle.

bash-3.2$ psql
psql: FATAL:  database "anand" does not exist
bash-3.2$

By default, psql tries to connect to dbname with the username its installed.

6. PostgreSQL comes with 3 default databases
i. template0
ii. template1
iii. postgres

The template0 and template1 databases are known as template databases. The teplate1 database can be changed to allow to created a localized template for any new db to create. The template0 exists so so that when you alter template1, you still have a pristine copy to fall back on.

By default, the new database will be created by cloning the standard system database template1.

The template0 database is normally marked datallowconn = false to prevent its modification.

If you have worked on Oracle 12c multitenant db, then you can think of template0 as CDB and template1 as PDB.

7. Two tablespaces are automatically created when the database cluster is initialized. The pg_global tablespace is used for shared system catalogs. The pg_default tablespace is the default tablespace of the template1 and template0 databases

8. As Oracle has Alert log, PostgreSQL has kind of similar logfile. In MAC installation, the location is /usr/local/var/log.

You can look at other installation options at

https://www.postgresql.org/download/

In the next blog post, I will show how to connect to database and different kind of start/stop mode.

 

 

“U” entries in MLOG$

Recently in a discussion with colleague, on what entries do MLOG$ have, the following was agreed to :-

1. “I” for insert
2. “D” for delete
3. “D” + “I” for update.

Along with the above entries, you might notice “U” also. The “U” entry is for update. But then, on what condition do we get “U” and when do we get “D” and “I” entries.

I have used “EMP” table as master table in the example

DBA@:1> CREATE MATERIALIZED VIEW "MV_EMP"
  ON PREBUILT TABLE WITHOUT REDUCED PRECISION
  USING INDEX
  REFRESH FAST ON DEMAND NEXT null
  WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
  USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
  AS SELECT * from EMP;
 
Materialized view created.

DBA@:1> insert into emp values (0001,'ANAND','DBA',7839,sysdate,3500,null,20);
 
1 row created.
 
DBA@:1> select * from emp where empno=0001;
 
     EMPNO ENAME      JOB	       MGR HIREDATE		      SAL	COMM	 DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
	 1 ANAND      DBA	      7839 2016.12.03 21:45:16	     3500		     20
 
col CHANGE_VECTOR$$ for a20
 
DBA@:1> select * from mlog$_emp;
 
     EMPNO SNAPTIME$$	       D O CHANGE_VECTOR$$	     XID$$
---------- ------------------- - - -------------------- ----------
	 1 4000.01.01 00:00:00 I N FEFF 		1.1259E+15

DBA@:1> exec dbms_mview.refresh('MV_EMP');
 
PL/SQL procedure successfully completed.

DBA@:1> select * from mlog$_emp;
 
no rows selected
 
DBA@:1> select * from RUPD$_EMP;
 
no rows selected

DBA@:1> update emp set empno=2 where empno=1;
 
1 row updated.
 
DBA@:1> commit;
 
Commit complete.
 
DBA@:1> select * from mlog$_emp;
 
     EMPNO SNAPTIME$$	       D O CHANGE_VECTOR$$	     XID$$
---------- ------------------- - - -------------------- ----------
	 1 4000.01.01 00:00:00 D O 0000 		4.2222E+15
	 2 4000.01.01 00:00:00 I N FFFF 		4.2222E+15

DBA@:1> ALTER SESSION SET EVENTS '10046 trace name context forever, level 8';
 
Session altered.
 
DBA@:1> exec dbms_mview.refresh('MV_EMP');
 
PL/SQL procedure successfully completed.

bdj59v5mx6tx9
/* MV_REFRESH (MRG) */ MERGE INTO "PRAKANAN_DBA"."MV_EMP" "SNA$" USING (SELECT CURRENT$."EMPNO",CURRENT$."ENAME",CURRENT$."JOB",CURRENT$."MGR",CURRENT$."HIREDATE",CURRENT$."SAL",CURRENT$."COMM",CURREN
T$."DEPTNO" FROM (SELECT "EMP"."EMPNO" "EMPNO","EMP"."ENAME" "ENAME","EMP"."JOB" "JOB","EMP"."MGR" "MGR","EMP"."HIREDATE" "HIREDATE","EMP"."SAL" "SAL","EMP"."COMM" "COMM","EMP"."DEPTNO" "DEPTNO" FROM
"EMP" "EMP") CURRENT$, (SELECT DISTINCT MLOG$."EMPNO" FROM "PRAKANAN_DBA"."MLOG$_EMP" MLOG$ WHERE "SNAPTIME$$" > :1 AND ("DMLTYPE$$" != 'D')) LOG$ WHERE CURRENT$."EMPNO" = LOG$."EMPNO")"AV$" ON ("SNA$
"."EMPNO" = "AV$"."EMPNO") WHEN MATCHED THEN UPDATE  SET "SNA$"."EMPNO" = "AV$"."EMPNO","SNA$"."ENAME" = "AV$"."ENAME","SNA$"."JOB" = "AV$"."JOB","SNA$"."MGR" = "AV$"."MGR","SNA$"."HIREDATE" = "AV$"."
HIREDATE","SNA$"."SAL" = "AV$"."SAL","SNA$"."COMM" = "AV$"."COMM","SNA$"."DEPTNO" = "AV$"."DEPTNO" WHEN NOT MATCHED THEN INSERT  (SNA$."EMPNO",SNA$."ENAME",SNA$."JOB",SNA$."MGR",SNA$."HIREDATE",SNA$."
SAL",SNA$."COMM",SNA$."DEPTNO") VALUES (AV$."EMPNO",AV$."ENAME",AV$."JOB",AV$."MGR",AV$."HIREDATE",AV$."SAL",AV$."COMM",AV$."DEPTNO")

In the above example, with an update, “D” and “I” entries are created.

Now, in which scenario, is “U” entry created :-

With the same table example, lets update a row

DBA@:1> update emp set job='DataEng' where JOB='DBA';

1 row updated.

DBA@:1> commit;

Commit complete.

DBA@:1> select * from MLOG$_EMP;

     EMPNO    SNAPTIME$$          D O CHANGE_VECTOR$$      XID$$
   ---------- ------------------- - - -------------------- ----------
            3 4000.01.01 00:00:00 U U 0800                 2.8148E+15

To conclude –

If you are updating a Primary Key column/Rowid column, you will see “D”(delete)+ “I”(Insert) on update(U). For rest of the cases, you will see just “U”.

Enabling Flashback – Be Cautious

Enabling flashback on 11.2.0.4 database can take minutes and cause multiple database wait events degrading database performance.

On a quite busy system, during the low peak hours, I tried to enable flashback on 11.2.0.4.6 version database and multiple sessions waited on

1. buffer exterminate
2. enq: SQ – contention
3. latch: cbc contention
4. SGA: allocation forcing component growth

PRAKANAN_DBA@:1> show parameter sga_target
 
NAME                           TYPE        VALUE
------------------------------ ----------- ---------------
sga_target                     big integer 0

23:35:40 PRAKANAN_DBA@:1> show parameter db_cache_size
NAME                           TYPE        VALUE
------------------------------ ----------- ------------
db_cache_size                  big integer 39G

23:35:53 PRAKANAN_DBA@:1> show parameter shared_pool
 
NAME                           TYPE        VALUE
------------------------------ ----------- -------------
shared_pool_reserved_size      big integer 128M
shared_pool_size               big integer 4G

23:36:21 PRAKANAN_DBA@:1> @free_memory_in_shared_pool.sql
 
POOL         NAME                            BYTES
------------ -------------------------- ----------
shared pool  free memory                 283039728

23:38:48 PRAKANAN_DBA@:1> @shared_pool_detail.sql
 
POOL         NAME                               MB
------------ -------------------------- ----------
shared pool  KGLH0                      785.823174
shared pool  SQLA                        592.82975
shared pool  free memory                269.572815
shared pool  db_block_hash_buckets      268.503906
shared pool  SQLP                       192.214272
shared pool  KKSSP                       191.37767
shared pool  FileOpenBlock              156.083519
shared pool  event statistics per sess  142.083984
shared pool  ksunfy : SSO free list     135.169922
shared pool  KGLHD                      132.602089
shared pool  Checkpoint queue              128.125
shared pool  dirty object counts array         128
shared pool  dbktb: trace buffer          117.1875
shared pool  ASH buffers                       100
shared pool  parameter table block      83.7121429
shared pool  KGLDA                      36.5461655
shared pool  object queue hash buckets          36
shared pool  procs: ksunfy              30.6129456
shared pool  transaction                30.5776443
shared pool  enqueue                    27.7831573

SQL> alter database flashback on;
 
Database altered.

23:41:28 PRAKANAN_DBA@:1> /
 
USERNAME                      SID    SERIAL# SPID       EVENT                          LAST_CALL_ET  WAIT_TIME SECONDS_IN_WAIT STATE               SQL_ID        SQL_CHILD_NUMBER PLAN_HASH_VALUE MODULE
------------------------- ------- ---------- ---------- ------------------------------ ------------ ---------- --------------- ------------------- ------------- ---------------- --------------- -------------------------
APPS_USER_2                  3458       9875 15518      SQL*Net message from client               0          0               0 WAITING             b4pav99kxux32                0      3764792327 SessionV2
PRAKANAN_DBA                 9290      35933 21649      SQL*Net message to client                 0         -1               0 WAITED SHORT TIME   8q6awbsup6jm5                0      1761607409 SQL*Plus
APPS_USER_2                  1963      13699 28348      buffer exterminate                        1          0               0 WAITING             2zrudchusrcwa                3               0 JDBC Thin Client
SQL_240                      7301      36487 28346      buffer exterminate                        1          0               0 WAITING             2zrudchusrcwa                3               0
APPS_USER_2                  7467      12721 28352      buffer exterminate                        1          0               0 WAITING             2zrudchusrcwa                3               0 JDBC Thin Client
APPS_USER_2                  9038      42107 28351      buffer exterminate                        1          0               0 WAITING             2zrudchusrcwa                3               0 JDBC Thin Client
APPS_USER_2                 11153      29227 28354      buffer exterminate                        1          0               0 WAITING             2zrudchusrcwa                3               0 JDBC Thin Client
APPS_USER_2                   438      52879 28356      buffer exterminate                        1          0               0 WAITING             2zrudchusrcwa                3               0 JDBC Thin Client
APPS_USER_2                  1449      29585 3901       read by other session                     0          0               0 WAITING             4n4u2qqbfcmhu                1      1270994832 ResourceMonitor
APPS_USER_2                  5405      26175 6055       latch: cache buffers chains               0         -1               0 WAITED SHORT TIME   4n4u2qqbfcmhu                1      1270994832 ResourceMonitor
APPS_USER_2                  7807       9423 6057       db file sequential read                   0          0               0 WAITING             2ksm378ta54rw                2       231135236 ResourceMonitor
APPS_USER_2                  2319      34579 12665      db file sequential read                   0          0               0 WAITING             4n4u2qqbfcmhu                1      1270994832 ResourceMonitor
APPS_USER_2                   570      11479 5193       read by other session                     0          0               0 WAITING             4n4u2qqbfcmhu                1      1270994832 ResourceMonitor
SYS                          7106      60689 14609      SGA: allocation forcing compon           11          0               0 WAITING             1pbrwgrgmfu40                0               0 sqlplus@
                                                        ent growth                                                                                                                                
APPS_USER_2                   196      22161 5270       read by other session                     0          0               0 WAITING             4n4u2qqbfcmhu                1      1270994832 ResourceMonitor
 
15 rows selected.
 
Elapsed: 00:00:00.45
23:41:29 PRAKANAN_DBA@:1> /
 
USERNAME                      SID    SERIAL# SPID       EVENT                          LAST_CALL_ET  WAIT_TIME SECONDS_IN_WAIT STATE               SQL_ID        SQL_CHILD_NUMBER PLAN_HASH_VALUE MODULE
------------------------- ------- ---------- ---------- ------------------------------ ------------ ---------- --------------- ------------------- ------------- ---------------- --------------- -------------------------
APPS_USER_2                   899      26003 12761      enq: TX - index contention                0          0               0 WAITING             7mvrrf2cr8w26                1      3334570644 ResourceMonitor
PRAKANAN_DBA                 9290      35933 21649      SQL*Net message to client                 0         -1               0 WAITED SHORT TIME   8q6awbsup6jm5                0      1761607409 SQL*Plus
SYS                          7106      60689 14609      SGA: allocation forcing compon           12          0               1 WAITING             1pbrwgrgmfu40                0               0 sqlplus@
                                                        ent growth 
 
Elapsed: 00:00:00.44
23:41:30 PRAKANAN_DBA@:1> /
 
USERNAME                      SID    SERIAL# SPID       EVENT                          LAST_CALL_ET  WAIT_TIME SECONDS_IN_WAIT STATE               SQL_ID        SQL_CHILD_NUMBER PLAN_HASH_VALUE MODULE
------------------------- ------- ---------- ---------- ------------------------------ ------------ ---------- --------------- ------------------- ------------- ---------------- --------------- -------------------------
APPS_USER_2                    45       5745 18731      db file sequential read                   0         -1               0 WAITED SHORT TIME   7mvrrf2cr8w26                0      3334570644 ResourceMonitor
PRAKANAN_DBA                 9290      35933 21649      SQL*Net message to client                 0         -1               0 WAITED SHORT TIME   8q6awbsup6jm5                0      1761607409 SQL*Plus
APPS_USER_2                 10446      23443 14617      SQL*Net message from client               0          5               0 WAITED KNOWN TIME   8tk54xvssnx13                0      3718310410 SessionV2
SYS                          7106      60689 14609      SGA: allocation forcing compon           13          0               2 WAITING             1pbrwgrgmfu40                0               0 sqlplus@
                                                        ent growth

23:42:17 PRAKANAN_DBA@:1> show parameter shared_pool
 
NAME                           TYPE        VALUE
------------------------------ ----------- ----------------------
shared_pool_reserved_size      big integer 128M
shared_pool_size               big integer 4224M

23:42:48 PRAKANAN_DBA@:1> @free_memory_in_shared_pool.sql
 
POOL         NAME                            BYTES
------------ -------------------------- ----------
shared pool  free memory                2147133056

PRAKANAN_DBA@:1> @hidden_param
Enter value for parameter: _memory_imm_mode_without_autosga
Enter value for 1: _memory_imm_mode_without_autosga
old  11: AND    a.ksppinm like DECODE(LOWER('%&parameter%'), 'all', a.ksppinm, LOWER('%&1%'))
new  11: AND    a.ksppinm like DECODE(LOWER('%_memory_imm_mode_without_autosga%'), 'all', a.ksppinm, LOWER('%_memory_imm_mode_without_autosga%'))
 
PARAMETER                             DESCRIPTION                    SESSION_VA INSTANCE_V
------------------------------------- ------------------------------ ---------- ----------
_memory_imm_mode_without_autosga      Allow immediate mode without   TRUE       TRUE
                                      sga/memory target

23:43:18 PRAKANAN_DBA@:1> select start_time,COMPONENT, PARAMETER, INITIAL_SIZE/1024/1024 "INITIAL_SIZE",FINAL_SIZE/1024/1024 "FINAL_SIZE", STATUS from v$SGA_RESIZE_OPS where start_time > sysdate -1 order by 1;
 
START_TIME          COMPONENT                                                        PARAMETER                                                                        INITIAL_SIZE FINAL_SIZE STATUS
------------------- ---------------------------------------------------------------- -------------------------------------------------------------------------------- ------------ ---------- ---------
2016.11.01 23:41:21 shared pool                                                      shared_pool_size                                                                         4096       4096 ERROR
2016.11.01 23:41:21 DEFAULT buffer cache                                             db_cache_size                                                                           39936      39936 ERROR
2016.11.01 23:41:31 DEFAULT buffer cache                                             db_cache_size                                                                           39936      39808 COMPLETE
2016.11.01 23:41:31 shared pool                                                      shared_pool_size                                                                         4096       4224 COMPLETE
 
23:43:33 PRAKANAN_DBA@:1> @shared_pool_resize_ops.sql
 
END                     OPER_TYPE     INITIAL_SIZE TARGET_SIZE FINAL_SIZE
----------------------- ------------- ------------ ----------- ----------
01-Nov-2016 23:41       GROW            4294967296  4429185024 4294967296
01-Nov-2016 23:41       GROW            4294967296  4429185024 4429185024
29-Nov-2015 09:01       STATIC                   0  4294967296 4294967296

23:43:56 PRAKANAN_DBA@:1> @shared_pool_detail.sql
 
POOL         NAME                               MB
------------ -------------------------- ----------
shared pool  free memory                2044.86245
shared pool  db_block_hash_buckets      268.503906
shared pool  KKSSP                      191.963104
shared pool  FileOpenBlock              156.083519
shared pool  event statistics per sess  142.083984
shared pool  ksunfy : SSO free list     135.169922
shared pool  Checkpoint queue              128.125
shared pool  dirty object counts array         128
shared pool  flashback generation buff  124.156067
shared pool  dbktb: trace buffer          117.1875
shared pool  ASH buffers                       100
shared pool  parameter table block      83.8214722
shared pool  object queue hash buckets          36
shared pool  procs: ksunfy              30.6129456
shared pool  transaction                30.5776443
shared pool  enqueue                    27.7831573
shared pool  buffer handles             25.1770096
shared pool  state objects              22.5323486
shared pool  write state object         19.9843826
shared pool  KGLH0                      18.8174286

Alert log :-

alter database flashback on
Starting background process RVWR
Tue Nov 01 23:40:08 2016
RVWR started with pid=6159, OS id=1030
Tue Nov 01 23:40:29 2016
Errors in file /dumps-01/diag/rdbms/db1/db1/trace/db1_ora_29214.trc:
ORA-00379: no free buffers available in buffer pool DEFAULT for block size 8K
ORA-00379: no free buffers available in buffer pool DEFAULT for block size 8K

Trace file shows --

Scanned into hot portion of LRU
Deadlock because all buffers pinned.
In set=527, bsz=8192, wsi=0, poolid=3, pool_name=DEFAULT
Buffers originally scanned and found pinned = [189 0], evict=189, aged=0
Buffers rescanned on auxiliary list = 0
Buffers rescanned on main list = 140
Buffers in working set 189 (0), hbufs=50, hbmax=50
Buffers on repl list main=189, aux=0
Scanned into hot portion of LRU
Deadlock because all buffers pinned.
In set=528, bsz=8192, wsi=0, poolid=3, pool_name=DEFAULT
Buffers originally scanned and found pinned = [185 1], evict=184, aged=0
Buffers rescanned on auxiliary list = 0
Buffers rescanned on main list = 136
Buffers in working set 185 (0), hbufs=50, hbmax=50
Buffers on repl list main=185, aux=0

*** 2016-11-01 23:40:29.473
dbkedDefDump(): Starting a non-incident diagnostic dump (flags=0x0, level=3, mask=0x0)
----- Error Stack Dump -----
ORA-00379: no free buffers available in buffer pool DEFAULT for block size 8K
ORA-00379: no free buffers available in buffer pool DEFAULT for block size 8K
----- SQL Statement (None) -----
Current SQL information unavailable - no cursor.

From Metalink Doc id 2195173.1

The normal behavior is that the flashback buffer is only allocated at mount time if flashback is already enabled, otherwise the flashback buffer is allocated later when the Database Administrator decides to enable flashback (either explicitly, or by creating the first restore point) but in the latter case, there is the possibility that the database performance may be impacted as the instance searches for the required amount of contiguous memory in shared pool to allocate to the flashback buffer.

The issue is related to

Bug 24838599 Turning on Flashback Database May Take Minutes to Complete and may cause errors ORA-4031 ORA-379″ Doc ID 24838599.8

Patch 24838599: TURNING ON FLASHBACK DATABASE TAKES 15 MINUTES TO COMPLETE

Post Install Instructions for Bug 24838599 – Turning on Flashback Database May Take Minutes to Complete (Doc ID 2195173.1)

Hope this helps!!

EM Express Login – Get Flash

I have 12c setup on OEL 6.7 on  OVM and while trying to access EM express, I was receiving the error

em_express_error

Just for the notes, a user can log into EM Express using URL

https://<hostname>:<port>/em

and port details can be found using

lsnrctl status | grep HTTP
or  
select dbms_xdb_config.getHttpsPort() from dual;

Clicking on the “Get Flash” takes you to abode flash page from where you can download the rpm for flash.

[root@oel67-12c Downloads]# ls -lrt
-rw-r--r-- 1 root root 7270732 May 30 11:43 flash-plugin-11.2.202.621-release.x86_64.rpm
[root@oel67-12c Downloads]#
[root@oel67-12c Downloads]# rpm -ivh flash-plugin-11.2.202.621-release.x86_64.rpm
Preparing... ########################################### [100%]
1:flash-plugin ########################################### [100%]
[root@oel67-12c Downloads]#

After installing the rpm I still received the same error.So lets debug

[root@oel67-12c Downloads]# cd /usr/lib64/mozilla/plugins/
[root@oel67-12c plugins]# ls -lrth
total 368K
-rwxr-xr-x. 1 root root 5.2K Jul 25  2010 librhythmbox-itms-detection-plugin.so
-rwxr-xr-x. 1 root root  78K Oct 28  2013 libtotem-narrowspace-plugin.so
-rwxr-xr-x. 1 root root  70K Oct 28  2013 libtotem-mully-plugin.so
-rwxr-xr-x. 1 root root 105K Oct 28  2013 libtotem-gmp-plugin.so
-rwxr-xr-x. 1 root root  97K Oct 28  2013 libtotem-cone-plugin.so
lrwxrwxrwx  1 root root   41 May 30 11:43 libflashplayer.so -> /usr/lib64/flash-plugin/libflashplayer.so

[root@oel67-12c plugins]# ls -lrt /usr/lib64/flash-plugin/libflashplayer.so
-rwxr-xr-x 1 root root 0 Apr 26 20:10 /usr/lib64/flash-plugin/libflashplayer.so

A zero byte file, something is wrong!!! I downloaded the .tar.gz version of the file from adobe and after untar

[root@oel67-12c Downloads]# ls -lrt
total 48064
drwxr-xr-x  6 1001  1001     4096 Apr 26 20:10 usr
-r--r--r--  1 1001  1001     4009 Apr 26 20:10 readme.txt
-rw-r--r--  1 1001  1001 19314752 Apr 26 20:10 libflashplayer.so
drwxr-xr-x  2 1001  1001     4096 Apr 26 20:10 LGPL
-rw-r--r--  1 root root   7270732 May 30 11:43 flash-plugin-11.2.202.621-release.x86_64.rpm
-rw-r--r--  1 root root  20408320 May 30 11:51 install_flash_player_11_linux.x86_64.tar

Hmmm, so the file is ~18MB. Lets copy the file to /usr/lib64/mozilla/plugins/ and change the permissions

[root@oel67-12c plugins]# cp -p /root/Downloads/libflashplayer.so .
[root@oel67-12c plugins]# ls -lrt
total 19232
-rwxr-xr-x. 1 root root     5264 Jul 25  2010 librhythmbox-itms-detection-plugin.so
-rwxr-xr-x. 1 root root    79752 Oct 28  2013 libtotem-narrowspace-plugin.so
-rwxr-xr-x. 1 root root    70904 Oct 28  2013 libtotem-mully-plugin.so
-rwxr-xr-x. 1 root root   106984 Oct 28  2013 libtotem-gmp-plugin.so
-rwxr-xr-x. 1 root root    99176 Oct 28  2013 libtotem-cone-plugin.so
-rw-r--r--  1 1001 1001 19314752 Apr 26 20:10 libflashplayer.so
[root@oel67-12c plugins]# chown root:root libflashplayer.so
[root@oel67-12c plugins]# chmod 775 libflashplayer.so

And, now lets refresh the page and there you go !!!

em_express

 

Fixed Table x$ktfbue has not statistics

While playing around 12.1.0.2 db, I ran my usual script to check tablespace usage details and it took ~59 secs (Elapsed: 00:00:59.02), which was high.
Ran the sql using “gather_plan_statistics” hint and below lines in the execution plan were of interest –

|  34 |      HASH GROUP BY                     |                    |      1 |      6 |      3 |00:00:58.68 |     129K|  54801 |  1160K|  1160K|  758K (0)|
|  35 |       VIEW                             | DBA_FREE_SPACE     |      1 |  21019 |     13 |00:00:00.01 |     129K|  54801 |       |       |          |
|  36 |        JOIN FILTER USE                 | :BF0000            |      1 |        |     13 |00:00:00.01 |     129K|  54801 |       |       |          |
|  37 |         UNION-ALL                      |                    |      1 |        |     19 |00:00:00.01 |     129K|  54801 |       |       |          |
|  38 |          NESTED LOOPS                  |                    |      1 |      1 |      0 |00:00:00.01 |       7 |      0 |       |       |          |
|  39 |           NESTED LOOPS                 |                    |      1 |      1 |      0 |00:00:00.01 |       7 |      0 |       |       |          |
|* 40 |            INDEX FULL SCAN             | I_FILE2            |      1 |      4 |      4 |00:00:00.01 |       1 |      0 |       |       |          |
|* 41 |            TABLE ACCESS CLUSTER        | FET$               |      4 |      1 |      0 |00:00:00.01 |       6 |      0 |       |       |          |
|* 42 |             INDEX UNIQUE SCAN          | I_TS#              |      4 |      1 |      4 |00:00:00.01 |       2 |      0 |       |       |          |
|* 43 |           TABLE ACCESS CLUSTER         | TS$                |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |
|* 44 |            INDEX UNIQUE SCAN           | I_TS#              |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |
|  45 |          NESTED LOOPS                  |                    |      1 |     10 |     10 |00:00:00.01 |      25 |      0 |       |       |          |
|  46 |           NESTED LOOPS                 |                    |      1 |     10 |     10 |00:00:00.01 |      21 |      0 |       |       |          |
|* 47 |            TABLE ACCESS FULL           | TS$                |      1 |      4 |      4 |00:00:00.01 |       9 |      0 |       |       |          |
|* 48 |            FIXED TABLE FIXED INDEX     | X$KTFBFE (ind:1)   |      4 |      2 |     10 |00:00:00.01 |      12 |      0 |       |       |          |
|* 49 |           INDEX UNIQUE SCAN            | I_FILE2            |     10 |      1 |     10 |00:00:00.01 |       4 |      0 |       |       |          |
|  50 |          NESTED LOOPS                  |                    |      1 |  21007 |      9 |00:00:57.85 |     129K|  54801 |       |       |          |
|* 51 |           HASH JOIN                    |                    |      1 |      7 |      9 |00:00:00.01 |      13 |      0 |  1115K|  1115K|  471K (0)|
|  52 |            NESTED LOOPS                |                    |      1 |      7 |      9 |00:00:00.01 |      12 |      0 |       |       |          |
|  53 |             NESTED LOOPS               |                    |      1 |     32 |      9 |00:00:00.01 |      11 |      0 |       |       |          |
|* 54 |              TABLE ACCESS FULL         | TS$                |      1 |      4 |      4 |00:00:00.01 |       9 |      0 |       |       |          |
|* 55 |              INDEX RANGE SCAN          | RECYCLEBIN$_TS     |      4 |      8 |      9 |00:00:00.01 |       2 |      0 |       |       |          |
|  56 |             TABLE ACCESS BY INDEX ROWID| RECYCLEBIN$        |      9 |      2 |      9 |00:00:00.01 |       1 |      0 |       |       |          |
|* 57 |            INDEX FULL SCAN             | I_FILE2            |      1 |      4 |      4 |00:00:00.01 |       1 |      0 |       |       |          |
|* 58 |           FIXED TABLE FULL             | X$KTFBUE           |      9 |   3125 |      9 |00:00:58.67 |     129K|  54801 |       |       |          |
|  59 |          NESTED LOOPS                  |                    |      1 |      1 |      0 |00:00:00.01 |      21 |      0 |       |       |          |
|  60 |           NESTED LOOPS                 |                    |      1 |      1 |      0 |00:00:00.01 |      21 |      0 |       |       |          |

Note
-----
   - dynamic statistics used: dynamic sampling (level=2)
   - this is an adaptive plan
   - 3 Sql Plan Directives used for this statement

The E-Rows for X$KTFBUE is 3125 whereas A-Rows 9. Checking the stats on the table

SYS@orcl:1> set serveroutput on
SYS@orcl:1>
SYS@orcl:1>
SYS@orcl:1> exec print_table('select * from dba_tab_statistics where  table_name=''X$KTFBUE'' ');
OWNER                         : SYS
TABLE_NAME                    : X$KTFBUE
PARTITION_NAME                :
PARTITION_POSITION            :
SUBPARTITION_NAME             :
SUBPARTITION_POSITION         :
OBJECT_TYPE                   : FIXED TABLE
NUM_ROWS                      :
BLOCKS                        :
EMPTY_BLOCKS                  :
AVG_SPACE                     :
CHAIN_CNT                     :
AVG_ROW_LEN                   :
AVG_SPACE_FREELIST_BLOCKS     :
NUM_FREELIST_BLOCKS           :
AVG_CACHED_BLOCKS             :
AVG_CACHE_HIT_RATIO           :
SAMPLE_SIZE                   :
LAST_ANALYZED                 :
GLOBAL_STATS                  :
USER_STATS                    :
STATTYPE_LOCKED               :
STALE_STATS                   :
SCOPE                         : SHARED
-----------------

Looking at the directive details shows missing details on “F(SYS.TS$) – F(SYS.UNDO$) – F(SYS.X$KTFBUE)”

SYS@orcl:1> exec  print_table('select * from DBA_SQL_PLAN_DIR_OBJECTS where owner=''SYS'' and object_name=''X$KTFBUE'' ');
DIRECTIVE_ID                  : 16383234857226438245
OWNER                         : SYS
OBJECT_NAME                   : X$KTFBUE
SUBOBJECT_NAME                :
OBJECT_TYPE                   : TABLE
NOTES                         : NONONOYES
-----------------

PL/SQL procedure successfully completed.

SYS@orcl:1> exec  print_table('select * from DBA_SQL_PLAN_DIRECTIVES where DIRECTIVE_ID=''16383234857226438245'' ');
DIRECTIVE_ID                  : 16383234857226438245
TYPE                          : DYNAMIC_SAMPLING
ENABLED                       : NO
STATE                         : USABLE
AUTO_DROP                     : YES
REASON                        : JOIN CARDINALITY MISESTIMATE
CREATED                       : 28-MAY-16 09.21.20.000000 PM
LAST_MODIFIED                 : 28-MAY-16 11.12.20.000000 PM
LAST_USED                     : 28-MAY-16 10.21.29.000000000 PM
NOTES                         : MISSING_STATSNO{F(SYS.TS$) - F(SYS.UNDO$) - F(SYS.X$KTFBUE)}
-----------------

PL/SQL procedure successfully completed.

Lets gather fixed object stats :-

SYS@orcl:1> exec DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;

PL/SQL procedure successfully completed.

Elapsed: 00:02:47.92

Ran the script again and it still took the same time, so checked the stats on X$KTFBUE and its still missing

SYS@orcl:1> exec print_table('select * from dba_tab_statistics where  table_name=''X$KTFBUE'' ');
OWNER                         : SYS
TABLE_NAME                    : X$KTFBUE
PARTITION_NAME                :
PARTITION_POSITION            :
SUBPARTITION_NAME             :
SUBPARTITION_POSITION         :
OBJECT_TYPE                   : FIXED TABLE
NUM_ROWS                      :
BLOCKS                        :
EMPTY_BLOCKS                  :
AVG_SPACE                     :
CHAIN_CNT                     :
AVG_ROW_LEN                   :
AVG_SPACE_FREELIST_BLOCKS     :
NUM_FREELIST_BLOCKS           :
AVG_CACHED_BLOCKS             :
AVG_CACHE_HIT_RATIO           :
SAMPLE_SIZE                   :
LAST_ANALYZED                 :
GLOBAL_STATS                  :
USER_STATS                    :
STATTYPE_LOCKED               :
STALE_STATS                   :
SCOPE                         : SHARED
-----------------

PL/SQL procedure successfully completed.

Reviewed few documents

Query Against DBA_EXTENTS Performs Slowly After Upgrade to 11.2.0.3 (Doc ID 1453425.1)
Bug 5259025 – The fixed table x$ktfbue has no statistics (Doc ID 5259025.8)

Gathered the stats on fixed table x$ktfbue

SYS@orcl:1>  exec DBMS_STATS.GATHER_TABLE_STATS('SYS','X$KTFBUE');

PL/SQL procedure successfully completed.

Elapsed: 00:00:34.09
SYS@orcl:1> exec print_table('select * from dba_tab_statistics where  table_name=''X$KTFBUE'' ');
OWNER                         : SYS
TABLE_NAME                    : X$KTFBUE
PARTITION_NAME                :
PARTITION_POSITION            :
SUBPARTITION_NAME             :
SUBPARTITION_POSITION         :
OBJECT_TYPE                   : FIXED TABLE
NUM_ROWS                      : 9581
BLOCKS                        :
EMPTY_BLOCKS                  :
AVG_SPACE                     :
CHAIN_CNT                     :
AVG_ROW_LEN                   : 47
AVG_SPACE_FREELIST_BLOCKS     :
NUM_FREELIST_BLOCKS           :
AVG_CACHED_BLOCKS             :
AVG_CACHE_HIT_RATIO           :
SAMPLE_SIZE                   : 9581
LAST_ANALYZED                 : 28-may-2016 22:55:47
GLOBAL_STATS                  : YES
USER_STATS                    : NO
STATTYPE_LOCKED               :
STALE_STATS                   :
SCOPE                         : SHARED
-----------------

Re-ran the sql script and Elapsed: 00:00:00.41