Professional Documents
Culture Documents
Shankarnag
EnterpriseDB
INDEX
Autovacuum
Vacuum
- 5
System Queries - 6
CTID
- 40
Func & Triggers - 47
Vacuum Demo :
create table trunc( id int);
insert into trunc VALUES (generate_series(1,10));
select ctid,id from trunc ;
delete from trunc where id % 2=0;
select ctid,id from trunc ;
VACUUM verbose trunc ;
insert into trunc VALUES (2);
postgres=# select ctid,id from trunc ;
System Queries
Find the number of live rows vs dead
rows of a table :select relname
as "Table",
n_live_tup
as "Live tuples",
n_dead_tup
as "Dead tuples"
from pg_stat_user_tables
where relname = 'my_table';
datname
as "Database",
numbackends
as "Backends",
xact_commit
as "Xact Committed",
xact_rollback
as "Xact Rolled Back",
blks_read
as "Blocks Read",
blks_hit
as "Blocks Hit",
(pg_database_size(datid) / 1024)::int as "Size (KB)"
FROM pg_stat_database db
WHERE UPPER(db.datname) != 'TEMPLATE0' AND
UPPER(db.datname) != 'TEMPLATE1'
ORDER BY "Database";
List sequences
SELECT relname as " Sequence
Name
FROM pg_class
WHERE relkind = 'S' AND
relnamespace IN ( SELECT oid FROM
pg_namespace WHERE nspname
NOT LIKE 'pg_%' AND nspname !=
'information_schema' );
idstat.idx_scan AS times_used,
pg_size_pretty(pg_relation_size(idstat.relname)) AS table_size,
pg_size_pretty(pg_relation_size(indexrelname)) AS index_size,
indexdef AS definition
Ex:
pg_sleep
---------(1 row)
now
---------------------------------2010-10-24 13:52:54.186517+05:30
(1 row)
pg_current_xlog_insert_location
Retrieves the current transaction log
insertion file name.
postgres=# select
pg_current_xlog_insert_location();
pg_current_xlog_insert_location
--------------------------------0/A000064
CTID Demo
postgres=# \d cluster
Did not find any relation named "cluster".
postgres=# \h cluster
Command:
CLUSTER
Description: cluster a table according to an index
Syntax:
CLUSTER tablename [ USING indexname ]
CLUSTER
postgres=# cluster emails;
ERROR: there is no previously clustered index for table "emails"
postgres=# VACUUM ANALYZE emails;
VACUUM
postgres=# select * from emails where ctid='(0,8)';
email
------(0 rows)
FUNCTIONS