PostgreSQL unlogged表

One type of table PostgreSQL interposed between normal and temporary tables, called unlogged table, the table also belong to the new index unlogged, the table does not write data to the persistent data is written when the write- ahead log file, after the database is abnormally shut down or crash abnormality data table will be the truncate out, but will be several times faster than the normal write performance on the table.

Tables were tested normal data insertion speed difference unlogged

uber_geocoder=# \dt+
                                      List of relations
          Schema          |          Name          | Type  |  Owner   |  Size  | Description 
--------------------------+------------------------+-------+----------+--------+-------------
 uber_geocoder_tw_15q3_v2 | compiling_info         | table | postgres | 16 kB  | 
 uber_geocoder_tw_15q3_v2 | data_process_reports   | table | postgres | 16 kB  | 
 uber_geocoder_tw_15q3_v2 | info                   | table | postgres | 16 kB  | 
 uber_geocoder_tw_15q3_v2 | twn_addr_compact       | table | postgres | 774 MB | 
(4 rows)

uber_geocoder=# \timing 
Timing is on.
uber_geocoder
=# create table twn_addr_compact_loggod as select * from twn_addr_compact ; SELECT 258902 Time: 977250.581 ms

Can be seen in the case of normal table and a new interpolated data of 770M took nearly 16 minutes

Unlogged a new table and insert test data 770M

uber_geocoder=# create unlogged table twn_addr_compact_unloggod as select * from twn_addr_compact ;
SELECT 258902
Time: 300683.321 ms

It can be seen under the same conditions unlogged table insertion speed of 5 minutes, three times performance improvement.

 Interest postgres process can kill off, and then start the database, you will find unlogged data table we just created is lost.

How to view all the current unlogged tables in the database

uber_geocoder=# select n.nspname as schema_name,c.relname as table_name from pg_catalog.pg_namespace n, pg_catalog.pg_class c where c.relnamespace=n.oid and n.nspname != 'pg_toast' and c.relpersistence = 'u';
       schema_name        |        table_name         
--------------------------+---------------------------
 edbstore                 | emp
 uber_geocoder_tw_15q3_v2 | twn_addr_compact_unloggod
(2 rows)

If you need to modify the batch will unlogged table as a normal table, do the following

uber_geocoder=# select 'ALTER TABLE'||' '||concat(n.nspname,'.' ,c.relname)||' '||'SET LOGGED ;' AS convert_logged_sql from pg_catalog.pg_namespace n, pg_catalog.pg_class c where c.relnamespace=n.oid and n.nspname != 'pg_toast' and c.relpersistence = 'u';
                             convert_logged_sql                              
-----------------------------------------------------------------------------
 ALTER TABLE edbstore.emp SET LOGGED ;
 ALTER TABLE uber_geocoder_tw_15q3_v2.twn_addr_compact_unloggod SET LOGGED ;
(2 rows)

 

Guess you like

Origin www.cnblogs.com/ilifeilong/p/11783565.html