SlideShare a Scribd company logo
1 of 5
Download to read offline
How to take a dump from a Wal
fi
le
♨ pg_walinspect♨
vs
📍 pg_waldump📍
View contents of WALs using pg_waldump:
1. First
fi
nd if you have `pg_waldump` in your system.
-> which pg_waldump -> pg_waldump not found
It is cool, just check if you have postgresql-contrib installed or not
If yes, then maybe like me you do not have it in path, so give absolute path
-> /usr/lib/postgresql/<PG-Version>/bin/pg_waldump
2. Now
fi
rst go to this directory /var/lib/postgresql/14/main/pg_wal/, you'll need root access
3. You'll see
fi
les like this "00000001000000000000000A", just pick any two subsequent
fi
les and
run it
4. This will run it and give output in wal_dump.txt
fi
le:
Example 1: dump all data between two wal
fi
le:
$ ./pg_waldump -p /var/lib/postgresql/14/main/pg_wal/ 00000001000000000000000A
00000001000000000000000B > ~/<Your-output-path>/wal_dump.txt
Example 2:
We want to see contents of a wal
fi
le from lsn1 to lsn2:
pg_waldump -s 76/7E000060 -e 76/7E000108 00000001000000760000007E
rmgr: Heap len (rec/tot): 57/ 57, tx: 59555584, lsn: 76/7E000060, prev 76/7E000028,
desc: INSERT+INIT o
ff
1
fl
ags 0x08, blkref #0: rel 1663/5/53434 blk 0
rmgr: Transaction len (rec/tot): 46/ 46, tx: 59555584, lsn: 76/7E0000A0, prev 76/7E000060,
desc: COMMIT 2023-02-13 16:25:19.441483 EST
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 76/7E0000D0, prev 76/7E0000A0, desc:
RUNNING_XACTS nextXid 59555585 latestCompletedXid 59555584 oldestRunningXid 59555585
Example 3:
postgres$ /usr/lib/postgresql/14/bin/pg_waldump -p /var/lib/postgresql/11/main/pg_wal -s
0/353AF21C -e 0/353BE51C
View details of WALs using pg_walinspect:
low-level WAL inspection
The pg_walinspect module available from postgres 15 above, provides SQL functions that allow
you to inspect the contents of write-ahead log of a running PostgreSQL database cluster at a low
level, which is useful for debugging, analytical, reporting or educational purposes. It is similar to
pg_waldump, but accessible through SQL rather than a separate utility.
All the functions of this module will provide the WAL information using the server's current
timeline ID.
Note
The pg_walinspect functions are often called using an LSN argument that speci
fi
es the location at
which a known WAL record of interest begins. However, some functions, such as
pg_logical_emit_message, return the LSN afterthe record that was just inserted.
Tip
All of the pg_walinspect functions that show information about records that fall within a certain
LSN range are permissive about accepting end_lsn arguments that are after the server's current
LSN.
Using an end_lsn “from the future” will not raise an error.
It may be convenient to provide the value FFFFFFFF/FFFFFFFF (the maximum valid pg_lsnvalue)
as an end_lsn argument.
This is equivalent to providing an end_lsn argument matching the server's current LSN.
By default, use of these functions is restricted to superusers and members of the
pg_read_server_
fi
les role. Access may be granted by superusers to others using GRANT.
General Functions
pg_get_wal_record_info(in_lsn pg_lsn) returns record.
Gets WAL record information about a record that is located at or after the in_lsn argument. For
example:
postgres=# SELECT * FROM pg_get_wal_record_info('0/E419E28');
+-------------------------------------
start_lsn | 0/E419E28
end_lsn | 0/E419E68
prev_lsn | 0/E419D78
xid | 0
resource_manager | Heap2
record_type | VACUUM
record_length | 58
main_data_length | 2
fpi_length | 0
description | nunused: 5, unused: [1, 2, 3, 4, 5]
block_ref | blkref #0: rel 1663/16385/1249-fork main blk 364
If in_lsn isn't at the start of a WAL record, information about the next valid WAL record is shown
instead.
If there is no next valid WAL record, the function raises an error.
pg_get_wal_records_info(start_lsn pg_lsn, end_lsn pg_lsn) returns setof record
Gets information of all the valid WAL records between start_lsn and end_lsn. Returns one row
per WAL record.
For example:
postgres=# SELECT * FROM pg_get_wal_records_info('0/1E913618', '0/1E913740') LIMIT 1;
-----------------------------------
start_lsn | 0/1E913618
end_lsn | 0/1E913650
prev_lsn | 0/1E9135A0
xid | 0
resource_manager | Standby
record_type | RUNNING_XACTS
record_length | 50
main_data_length | 24
fpi_length | 0
description | nextXid 33775-latestCompletedXid 33774 oldestRunningXid 33775
block_ref |
The function raises an error if start_lsn is not available.
pg_get_wal_block_info(start_lsn pg_lsn, end_lsn pg_lsn, show_data boolean DEFAULT true)
returns setof record
Gets information about each block reference from all the valid WAL records between start_lsn
and end_lsn with one or more block references. Returns one row per block reference per WAL
record.
The
fi
rst step, is to install the extension, which does not di
ff
er from any other extension:
postgres=# CREATE EXTENSION pg_walinspect;
This extension allows us to examine the records between two valid WAL Log Sequence Number
(LSN in short): start_lsn and end_lsn.
Those LSN can be obtained through the pg_current_wal_lsn function
postgres=# SELECT pg_current_wal_lsn(),now();
pg_current_wal_lsn | now
+-------------------------------
0/1230278 | 2024-01-12 15:51:21.532482-03
(1 row)
Now we doing some dml on database and get new LSN:'0/12302B8'
Now we can using this functions to investigate between 2 mentiond Lsn:
postgres=# SELECT * FROM pg_get_wal_block_info('0/1230278', '0/12302B8');
-----------------------------------
start_lsn | 0/1230278
end_lsn | 0/12302B8
prev_lsn | 0/122FD40
block_id | 0
reltablespace | 1663
reldatabase | 1
rel
fi
lenode | 2658
relforknumber | 0
relblocknumber | 11
xid | 341
resource_manager | Btree
record_type | INSERT_LEAF
record_length | 64
main_data_length | 2
block_data_length | 16
block_fpi_length | 0
block_fpi_info |
description | o
ff
: 46
block_data | -x00002a00070010402630000070696400
block_fpi_data |
This example involves a WAL record that only contains one block reference, but many WAL
records contain several block references. Rows output by pg_get_wal_block_info are guaranteed
to have a unique combination of start_lsn and block_id values.
Much of the information shown here matches the output that pg_get_wal_records_infowould
show, given the same arguments. However, pg_get_wal_block_info unnests the information from
each WAL record into an expanded form by outputting one row per block reference, so certain
details are tracked at the block reference level rather than at the whole-record level. This structure
is useful with queries that track how individual blocks changed over time. Note that records with
no block references (e.g., COMMIT WAL records) will have no rows returned, so
pg_get_wal_block_info may actually return fewer rows than pg_get_wal_records_info.
The reltablespace, reldatabase, and rel
fi
lenode parameters reference pg_tablespace.oid,
pg_database.oid, and pg_class.rel
fi
lenode respectively. The relforknumber
fi
eld is the fork number
within the relation for the block reference.
Tip
The pg_
fi
lenode_relation function can help you to determine which relation was modi
fi
ed during
original execution.
It is possible for clients to avoid the overhead of materializing block data. This may make function
execution signi
fi
cantly faster.
When show_data is set to false, block_data and block_fpi_data values are omitted (that is, the
block_data and block_fpi_data OUT arguments are NULL for all rows returned).
Obviously, this optimization is only feasible with queries where block data isn't truly required.
The function raises an error if start_lsn is not available.
pg_get_wal_stats(start_lsn pg_lsn, end_lsn pg_lsn, per_record boolean DEFAULT false) returns
setof record
Gets statistics of all the valid WAL records between start_lsn and end_lsn. By default, it returns
one row per resource_manager type. When per_record is set to true, it returns one row per
record_type.
For example:
postgres=# SELECT * FROM pg_get_wal_stats('0/1E847D00', '0/1E84F500')
WHERE count > 0 AND
"resource_manager/record_type" ='Transaction' LIMIT 1;
+-------------------
resource_manager/record_type | Transaction
count | 2
count_percentage | 8
record_size | 875
record_size_percentage | 41.23468426013195
fpi_size | 0
fpi_size_percentage | 0
combined_size | 875
combined_size_percent | 2.8634072910530795
The function raises an error if start_lsn is not available.
♨ ♨ ♨ ♨ ♨ ♨ ♨ ♨ ♨ ♨
Regards,
Alireza Kamrani,
Senior RDBMS Consultant.

More Related Content

Similar to How to take a dump from a Wal file PostgreSQL

PostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_CheatsheetPostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_CheatsheetLucian Oprea
 
Lavigne bsdmag may13
Lavigne bsdmag may13Lavigne bsdmag may13
Lavigne bsdmag may13Dru Lavigne
 
Pluggable Pipelines
Pluggable PipelinesPluggable Pipelines
Pluggable Pipelinessetitesuk
 
5 - ch3.pptx
5 - ch3.pptx5 - ch3.pptx
5 - ch3.pptxTemp35704
 
Walbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logWalbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logHans-Jürgen Schönig
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomValeriy Kravchuk
 
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Gulcin Yildirim Jelinek
 
Event Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data ProcessorsEvent Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data ProcessorsInvenire Aude
 
systemverilog-interview-questions.docx
systemverilog-interview-questions.docxsystemverilog-interview-questions.docx
systemverilog-interview-questions.docxssuser1c8ca21
 
12c Database new features
12c Database new features12c Database new features
12c Database new featuresSandeep Redkar
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki LinnakangasPG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangaspgdayrussia
 
515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptxssuser03ec3c
 
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...Ontico
 
LiveAction Spanning Tree Protocol (STP) Application Note
LiveAction Spanning Tree Protocol (STP) Application NoteLiveAction Spanning Tree Protocol (STP) Application Note
LiveAction Spanning Tree Protocol (STP) Application NoteActionPacked Networks
 

Similar to How to take a dump from a Wal file PostgreSQL (20)

PostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_CheatsheetPostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_Cheatsheet
 
Lavigne bsdmag may13
Lavigne bsdmag may13Lavigne bsdmag may13
Lavigne bsdmag may13
 
Pluggable Pipelines
Pluggable PipelinesPluggable Pipelines
Pluggable Pipelines
 
5 - ch3.pptx
5 - ch3.pptx5 - ch3.pptx
5 - ch3.pptx
 
SIP Tutorial/Workshop 2
SIP Tutorial/Workshop 2SIP Tutorial/Workshop 2
SIP Tutorial/Workshop 2
 
Plproxy
PlproxyPlproxy
Plproxy
 
Walbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction logWalbouncer: Filtering PostgreSQL transaction log
Walbouncer: Filtering PostgreSQL transaction log
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
 
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
 
systemd
systemdsystemd
systemd
 
Event Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data ProcessorsEvent Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data Processors
 
systemverilog-interview-questions.docx
systemverilog-interview-questions.docxsystemverilog-interview-questions.docx
systemverilog-interview-questions.docx
 
12c Database new features
12c Database new features12c Database new features
12c Database new features
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
Postgres clusters
Postgres clustersPostgres clusters
Postgres clusters
 
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki LinnakangasPG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
 
515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx
 
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
 
SQL Server vs Postgres
SQL Server vs PostgresSQL Server vs Postgres
SQL Server vs Postgres
 
LiveAction Spanning Tree Protocol (STP) Application Note
LiveAction Spanning Tree Protocol (STP) Application NoteLiveAction Spanning Tree Protocol (STP) Application Note
LiveAction Spanning Tree Protocol (STP) Application Note
 

More from Alireza Kamrani

Oracle database maximum performance on Exadata
Oracle database maximum performance on ExadataOracle database maximum performance on Exadata
Oracle database maximum performance on ExadataAlireza Kamrani
 
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdfClone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdfAlireza Kamrani
 
Flashback time travel vs Flash back Data Archive.pdf
Flashback time travel  vs Flash back Data Archive.pdfFlashback time travel  vs Flash back Data Archive.pdf
Flashback time travel vs Flash back Data Archive.pdfAlireza Kamrani
 
Import option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdfImport option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdfAlireza Kamrani
 
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdfAlireza Kamrani
 
Recovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdfRecovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdfAlireza Kamrani
 
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdfAlireza Kamrani
 
♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instanceAlireza Kamrani
 
Out-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden ImagesOut-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden ImagesAlireza Kamrani
 
IO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performanceIO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performanceAlireza Kamrani
 
The Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAsThe Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAsAlireza Kamrani
 
What is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of databaseWhat is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of databaseAlireza Kamrani
 
🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...Alireza Kamrani
 
Oracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking featuresOracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking featuresAlireza Kamrani
 
Store non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSONStore non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSONAlireza Kamrani
 
Enhancements in Oracle 23c Introducing the NewOld Returning Clause
Enhancements in Oracle 23c Introducing the NewOld Returning ClauseEnhancements in Oracle 23c Introducing the NewOld Returning Clause
Enhancements in Oracle 23c Introducing the NewOld Returning ClauseAlireza Kamrani
 
PostgreSQL vs Oracle a brief comparison
PostgreSQL vs Oracle a brief  comparisonPostgreSQL vs Oracle a brief  comparison
PostgreSQL vs Oracle a brief comparisonAlireza Kamrani
 

More from Alireza Kamrani (17)

Oracle database maximum performance on Exadata
Oracle database maximum performance on ExadataOracle database maximum performance on Exadata
Oracle database maximum performance on Exadata
 
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdfClone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
 
Flashback time travel vs Flash back Data Archive.pdf
Flashback time travel  vs Flash back Data Archive.pdfFlashback time travel  vs Flash back Data Archive.pdf
Flashback time travel vs Flash back Data Archive.pdf
 
Import option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdfImport option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdf
 
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
 
Recovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdfRecovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdf
 
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
 
♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance
 
Out-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden ImagesOut-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden Images
 
IO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performanceIO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performance
 
The Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAsThe Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAs
 
What is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of databaseWhat is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of database
 
🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...
 
Oracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking featuresOracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking features
 
Store non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSONStore non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSON
 
Enhancements in Oracle 23c Introducing the NewOld Returning Clause
Enhancements in Oracle 23c Introducing the NewOld Returning ClauseEnhancements in Oracle 23c Introducing the NewOld Returning Clause
Enhancements in Oracle 23c Introducing the NewOld Returning Clause
 
PostgreSQL vs Oracle a brief comparison
PostgreSQL vs Oracle a brief  comparisonPostgreSQL vs Oracle a brief  comparison
PostgreSQL vs Oracle a brief comparison
 

Recently uploaded

Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 

Recently uploaded (20)

Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 

How to take a dump from a Wal file PostgreSQL

  • 1. How to take a dump from a Wal fi le ♨ pg_walinspect♨ vs 📍 pg_waldump📍 View contents of WALs using pg_waldump: 1. First fi nd if you have `pg_waldump` in your system. -> which pg_waldump -> pg_waldump not found It is cool, just check if you have postgresql-contrib installed or not If yes, then maybe like me you do not have it in path, so give absolute path -> /usr/lib/postgresql/<PG-Version>/bin/pg_waldump 2. Now fi rst go to this directory /var/lib/postgresql/14/main/pg_wal/, you'll need root access 3. You'll see fi les like this "00000001000000000000000A", just pick any two subsequent fi les and run it 4. This will run it and give output in wal_dump.txt fi le: Example 1: dump all data between two wal fi le: $ ./pg_waldump -p /var/lib/postgresql/14/main/pg_wal/ 00000001000000000000000A 00000001000000000000000B > ~/<Your-output-path>/wal_dump.txt Example 2: We want to see contents of a wal fi le from lsn1 to lsn2: pg_waldump -s 76/7E000060 -e 76/7E000108 00000001000000760000007E rmgr: Heap len (rec/tot): 57/ 57, tx: 59555584, lsn: 76/7E000060, prev 76/7E000028, desc: INSERT+INIT o ff 1 fl ags 0x08, blkref #0: rel 1663/5/53434 blk 0 rmgr: Transaction len (rec/tot): 46/ 46, tx: 59555584, lsn: 76/7E0000A0, prev 76/7E000060, desc: COMMIT 2023-02-13 16:25:19.441483 EST rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 76/7E0000D0, prev 76/7E0000A0, desc: RUNNING_XACTS nextXid 59555585 latestCompletedXid 59555584 oldestRunningXid 59555585 Example 3: postgres$ /usr/lib/postgresql/14/bin/pg_waldump -p /var/lib/postgresql/11/main/pg_wal -s 0/353AF21C -e 0/353BE51C View details of WALs using pg_walinspect:
  • 2. low-level WAL inspection The pg_walinspect module available from postgres 15 above, provides SQL functions that allow you to inspect the contents of write-ahead log of a running PostgreSQL database cluster at a low level, which is useful for debugging, analytical, reporting or educational purposes. It is similar to pg_waldump, but accessible through SQL rather than a separate utility. All the functions of this module will provide the WAL information using the server's current timeline ID. Note The pg_walinspect functions are often called using an LSN argument that speci fi es the location at which a known WAL record of interest begins. However, some functions, such as pg_logical_emit_message, return the LSN afterthe record that was just inserted. Tip All of the pg_walinspect functions that show information about records that fall within a certain LSN range are permissive about accepting end_lsn arguments that are after the server's current LSN. Using an end_lsn “from the future” will not raise an error. It may be convenient to provide the value FFFFFFFF/FFFFFFFF (the maximum valid pg_lsnvalue) as an end_lsn argument. This is equivalent to providing an end_lsn argument matching the server's current LSN. By default, use of these functions is restricted to superusers and members of the pg_read_server_ fi les role. Access may be granted by superusers to others using GRANT. General Functions pg_get_wal_record_info(in_lsn pg_lsn) returns record. Gets WAL record information about a record that is located at or after the in_lsn argument. For example: postgres=# SELECT * FROM pg_get_wal_record_info('0/E419E28'); +------------------------------------- start_lsn | 0/E419E28 end_lsn | 0/E419E68 prev_lsn | 0/E419D78 xid | 0 resource_manager | Heap2 record_type | VACUUM record_length | 58 main_data_length | 2 fpi_length | 0 description | nunused: 5, unused: [1, 2, 3, 4, 5] block_ref | blkref #0: rel 1663/16385/1249-fork main blk 364 If in_lsn isn't at the start of a WAL record, information about the next valid WAL record is shown instead. If there is no next valid WAL record, the function raises an error. pg_get_wal_records_info(start_lsn pg_lsn, end_lsn pg_lsn) returns setof record Gets information of all the valid WAL records between start_lsn and end_lsn. Returns one row per WAL record. For example: postgres=# SELECT * FROM pg_get_wal_records_info('0/1E913618', '0/1E913740') LIMIT 1; ----------------------------------- start_lsn | 0/1E913618 end_lsn | 0/1E913650
  • 3. prev_lsn | 0/1E9135A0 xid | 0 resource_manager | Standby record_type | RUNNING_XACTS record_length | 50 main_data_length | 24 fpi_length | 0 description | nextXid 33775-latestCompletedXid 33774 oldestRunningXid 33775 block_ref | The function raises an error if start_lsn is not available. pg_get_wal_block_info(start_lsn pg_lsn, end_lsn pg_lsn, show_data boolean DEFAULT true) returns setof record Gets information about each block reference from all the valid WAL records between start_lsn and end_lsn with one or more block references. Returns one row per block reference per WAL record. The fi rst step, is to install the extension, which does not di ff er from any other extension: postgres=# CREATE EXTENSION pg_walinspect; This extension allows us to examine the records between two valid WAL Log Sequence Number (LSN in short): start_lsn and end_lsn. Those LSN can be obtained through the pg_current_wal_lsn function postgres=# SELECT pg_current_wal_lsn(),now(); pg_current_wal_lsn | now +------------------------------- 0/1230278 | 2024-01-12 15:51:21.532482-03 (1 row) Now we doing some dml on database and get new LSN:'0/12302B8' Now we can using this functions to investigate between 2 mentiond Lsn: postgres=# SELECT * FROM pg_get_wal_block_info('0/1230278', '0/12302B8'); ----------------------------------- start_lsn | 0/1230278 end_lsn | 0/12302B8 prev_lsn | 0/122FD40 block_id | 0 reltablespace | 1663 reldatabase | 1 rel fi lenode | 2658 relforknumber | 0 relblocknumber | 11 xid | 341 resource_manager | Btree record_type | INSERT_LEAF
  • 4. record_length | 64 main_data_length | 2 block_data_length | 16 block_fpi_length | 0 block_fpi_info | description | o ff : 46 block_data | -x00002a00070010402630000070696400 block_fpi_data | This example involves a WAL record that only contains one block reference, but many WAL records contain several block references. Rows output by pg_get_wal_block_info are guaranteed to have a unique combination of start_lsn and block_id values. Much of the information shown here matches the output that pg_get_wal_records_infowould show, given the same arguments. However, pg_get_wal_block_info unnests the information from each WAL record into an expanded form by outputting one row per block reference, so certain details are tracked at the block reference level rather than at the whole-record level. This structure is useful with queries that track how individual blocks changed over time. Note that records with no block references (e.g., COMMIT WAL records) will have no rows returned, so pg_get_wal_block_info may actually return fewer rows than pg_get_wal_records_info. The reltablespace, reldatabase, and rel fi lenode parameters reference pg_tablespace.oid, pg_database.oid, and pg_class.rel fi lenode respectively. The relforknumber fi eld is the fork number within the relation for the block reference. Tip The pg_ fi lenode_relation function can help you to determine which relation was modi fi ed during original execution. It is possible for clients to avoid the overhead of materializing block data. This may make function execution signi fi cantly faster. When show_data is set to false, block_data and block_fpi_data values are omitted (that is, the block_data and block_fpi_data OUT arguments are NULL for all rows returned). Obviously, this optimization is only feasible with queries where block data isn't truly required. The function raises an error if start_lsn is not available. pg_get_wal_stats(start_lsn pg_lsn, end_lsn pg_lsn, per_record boolean DEFAULT false) returns setof record Gets statistics of all the valid WAL records between start_lsn and end_lsn. By default, it returns one row per resource_manager type. When per_record is set to true, it returns one row per record_type. For example: postgres=# SELECT * FROM pg_get_wal_stats('0/1E847D00', '0/1E84F500') WHERE count > 0 AND "resource_manager/record_type" ='Transaction' LIMIT 1; +------------------- resource_manager/record_type | Transaction count | 2
  • 5. count_percentage | 8 record_size | 875 record_size_percentage | 41.23468426013195 fpi_size | 0 fpi_size_percentage | 0 combined_size | 875 combined_size_percent | 2.8634072910530795 The function raises an error if start_lsn is not available. ♨ ♨ ♨ ♨ ♨ ♨ ♨ ♨ ♨ ♨ Regards, Alireza Kamrani, Senior RDBMS Consultant.