Subscribe to Posts by Email

Subscriber Count

    699

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

Postgres for Oracle DBA

A quick features, commands, tools comparison of Postgres Database for Oracle DBA.

Oracle 
Architecturehttps://www.linkedin.com/pulse/postgresql-architecture-sumeet-shukla-1/
SGAPostgres memory is divided into shared memory and per backend memory which acts as SGA
BufferPoolshared buffers
Shared PoolOther buffer
log bufferwal buffers
pgawork mem, temp buffer, maintenance work buffer, catalog cache, optimize executor
Dictionarypg_catalog, pg_information_schema,
spfile/pfilein pgdata folder postgresql.conf
sqlnet.orain pgdata folder pg_hba.conf
Database Serverps -eaf | grep postgres
Database Clientpsql
Database ListenerUnix level socket , created in pgdata folder or defined by pid option in conf file , daemon process
redologwal files resided in pgdata folder under pg_wal directory
archivesarchive files resided in pgdata folder under archives directory when archive=on in conf file
databasecan have multiple databases under one postgresql instance
schema is mapped to user 1:1logically segregated under a database , a database can have multiple schemas and a user can access multiple scehamas 
sys schema or userpostgres database by default created and a public schema is associated with it
datafilephysically stored in base directory under pgdata, each folder will have a number represented by dbid
alertlogpostgresql-day.log under pgdata/pg_log directory
shutdownpg_ctl -stop -d <datadirectory>
startuppg_ctl -start -d <datadirectory>
expdppg_dump
impdppsql < sqldump file
expdp full 
expdp schema 
expdp table 
impdp full database 
impdp only metadata 
V$DATABASEPG_DATABASE
V$SESSIONPG_STAT_ACTIVITY
DBA_USERSPG_USER
DBA_TABLESPG_TABLES
DBA_ROLESPG_ROLES
DBA_TAB_COLSPG_ATTRIBUTE
V$LOCKED_OBJECTPG_LOCKS
V$PARAMETERPG_SETTINGS
V$SYSSTATPG_STAT_DATABASE
DBA_TAB_PRIVSTABLE_PRIVILEGES
V$SEGSTATPG_STATIO_ALL_TABLES
v$ viewsStatistic collection views- Subsystem that collects runtime dynamic information about certain server activities such as statistical performance information. Some of these tables could be thought as comparable to Oracle V$ views. - pg_stat*
dba_objects, dba_tables etcSystem catalog tables - Static metadata regarding the PostgreSQL database and static information about schema objects. Some of these tables could be thought as comparable to Oracle DBA_* Data Dictionary tables. - pg_catalog
user_objects, user_tablesInformation schema tables - Set of views that contain information about the objects defined in the current database. The information schema is specified by the SQL standard and as such, supported by PostgreSQL. Some of these tables could be thought as comparable to Oracle USER_* Data Dictionary tables. information_schema
identify locks (12>)SELECT blocked_locks.pid     AS blocked_pid,
         blocked_activity.usename  AS blocked_user,
         blocking_locks.pid     AS blocking_pid,
         blocking_activity.usename AS blocking_user,
         substring(blocked_activity.query,1,50)    AS blocked_statement,
         substring(blocking_activity.query,1,50)   AS current_statement_in_blocking_process
   FROM  pg_catalog.pg_locks         blocked_locks
    JOIN pg_catalog.pg_stat_activity blocked_activity  ON blocked_activity.pid = blocked_locks.pid
    JOIN pg_catalog.pg_locks         blocking_locks
        ON blocking_locks.locktype = blocked_locks.locktype
        AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database
        AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
        AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
        AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple
        AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid
        AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid
        AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid
        AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid
        AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid
        AND blocking_locks.pid != blocked_locks.pid
    JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
   WHERE NOT blocked_locks.granted;
identify locks 9.6SELECT a.datname,
         l.relation::regclass,
         l.transactionid,
         l.mode,
         l.GRANTED,
         a.usename,
         substring(a.query,1,80),
         a.query_start,
         age(now(), a.query_start) AS "age",
         a.pid
FROM pg_stat_activity a
JOIN pg_locks l ON l.pid = a.pid and mode='RowExclusiveLock'
ORDER BY a.query_start;
Kill one blocking sessionSELECT pg_cancel_backend(<pid of the process>)

SELECT pg_terminate_backend(<pid of the process>);
Kill all blocking session for particular dbSELECT
    pg_terminate_backend(pid)
FROM
    pg_stat_activity
WHERE
    — don’t kill my own connection!
    pid pg_backend_pid()
    — don’t kill the connections to other databases
    AND datname = 'databasename'
connections by user,database,stateselect state,usename,datname,count(*) from pg_stat_activity group by state,usename,datname;
long running sessions ex: more than 5 minsSELECT
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query,
  state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
oldest transaction in dbSELECT max(now() - xact_start) FROM pg_stat_activity  WHERE state IN ('idle in transaction', 'active');
Table & Index frag checkSELECT
  relname  as table_name,
  pg_size_pretty(pg_total_relation_size(relid)) As "Total Size",
  pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "Index Size",
  pg_size_pretty(pg_relation_size(relid)) as "Actual Size"
  FROM pg_catalog.pg_statio_user_tables
RDER BY pg_total_relation_size(relid) DESC;
manually collect stats on postgresanalyze table or analyze index
Create Usercreate user U with password '' superuser/nosuperuser;
Connect, resource privilegesgrant connect on database to user;
grant usage,select on schema s1 to user;
switch database\c dbname
swtich shema, user
alter session set current_schema=user;
set search_path schemaname;
stats collectionanalyze 
explain planexplain select statement
 shared_buffers parameter default 128, but if you increase you must increase bg_writer parameters
control shared memorywork_memory
control backend memory 
Check point parameters 
 readonly slaves 
StandbyREPMGR
DGMGRLRepmgr conf file
DGMGRL set propertiesforce_parallel_mode
replica sync check 
enable parallelism 
 called as gather node
parallelism - coordinatecalled as worker ndoe
parallelsim - px slavemax_worker_processes – Maximum number of background processes that can be launched to support parallel queries.
parallel_processesmax_parallel_workers – Maximum number of workers that support parallel operations.
 max_parallel_workers_per_gather (default 0) – Number of additional workers that can be used on a query.
degree on a objectparallel_tuple_cost (default 0.1) – Estimates the cost of transferring one tuple from a parallel worker process to another process
 parallel_setup_cost (default 1000.0) – Estimates the cost of launching parallel worker processes
 min_parallel_relation_size (default 8 MB) – A relation larger than this parameter is considered for parallel scans
consider the table size for default parallelimsforce_parallel_mode (default off) – This is useful when testing parallel query scans even when there is no performance benefit
SSL#ssl = off
#ssl_ca_file = ''
#ssl_cert_file = 'server.crt'
#ssl_crl_file = ''
#ssl_key_file = 'server.key'

Enable hostssl at pg_hba.conf
Changing bulk tables owner and sequence to new userdo $$
declare row record;
begin
  for row in select tablename as name from pg_tables where tableowner = 'memorystudiodbprd_admin' loop
    raise notice 'row: %', row;
    execute format('alter table "%s" owner to memorystudioecdc_admin', row.name);
  end loop;
end; $$;

do $$
declare row record;
begin
  for row in select sequencename as name from pg_sequences where sequenceowner = 'memorystudiodbprd_admin' loop
    raise notice 'row: %', row;
    execute format('alter sequence "%s" owner to memorystudioecdc_admin', row.name);
  end loop;
end; $$;
changin single table owner and seuqence to useralter sequence sequencename owner to newowner;
alter tablename  tablename owner to newowner;
User that’s has privileges on a tableSELECT *
FROM
(
SELECT
    schemaname
    ,objectname
    ,usename
    ,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, 'select') AND has_schema_privilege(usrs.usename, schemaname, 'usage')  AS sel
    ,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, 'insert') AND has_schema_privilege(usrs.usename, schemaname, 'usage')  AS ins
    ,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, 'update') AND has_schema_privilege(usrs.usename, schemaname, 'usage')  AS upd
    ,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, 'delete') AND has_schema_privilege(usrs.usename, schemaname, 'usage')  AS del
,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj,  'alter') AND has_schema_privilege(usrs.usename, schemaname,  'usage') AS alt
    ,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, 'references') AND has_schema_privilege(usrs.usename, schemaname, 'usage')  AS ref
FROM
    (
    SELECT schemaname, 't' AS obj_type, tablename AS objectname, schemaname + '.' + tablename AS fullobj FROM pg_tables
    UNION
    SELECT schemaname, 'v' AS obj_type, viewname AS objectname, schemaname + '.' + viewname AS fullobj FROM pg_views
    ) AS objs
    ,(SELECT * FROM pg_user) AS usrs
ORDER BY fullobj
)
WHERE (sel = true or ins = true or upd = true or del = true or ref = true)
and objectname = 'd_app_map_group' and usename='fpradmin';
Check connections uses ssl or not select pg_ssl.pid, pg_ssl.ssl, pg_ssl.version,
           pg_sa.backend_type, pg_sa.usename, pg_sa.client_addr
           from pg_stat_ssl pg_ssl
           join pg_stat_activity pg_sa
             on pg_ssl.pid = pg_sa.pid;