Atikh's DBA blog
  • Home
  • Oracle
  • MySQL
  • MongoDB
  • PostgreSQL
  • Snowflake
  • About Me
  • Contact Us

Physical location of datafiles in PostgreSQL

 Atikh Shaikh     PostgreSQL     1 comment   

In this article, we will discuss finding the physical location of data files for a particular database.
In the logical structure, we can see different databases and tables or any other objects under it but as DBA we should also be aware of how to find out the location of data files associated with a database or a table.
In the article table creation in Postgres database we learned to create tables now we use the same tables here to perform a demonstration. Assume we have the below details

Database name- tech_db
Table name - employee

tech_db=# \c tech_db
You are now connected to database "tech_db" as user "postgres".
tech_db=# \dt
          List of relations
 Schema |   Name   | Type  |  Owner
--------+----------+-------+----------
 public | employee | table | postgres
(1 row)

tech_db=# select * from employee;
 emp_id | emp_name | age
--------+----------+-----
    123 | sam      |  25
    124 | John     |  24
(2 rows)

as of now we do not physical location of this database or table, now we will try to find out the same

Read More : Database Creation in PostgreSQL

Data Directory

First of all check data directory using show command

tech_db=# show data_directory;
  data_directory
------------------
 E:/postgres/data
(1 row)

Above we got data directory, as by default folders for each database gets created under data_directory/base location

data-directory-postgresql

as we see folder as created with some random numbers which is called as OID , value of OID can be find using below query.

tech_db=# select datname, oid from pg_database where datname='tech_db';
 datname |  oid
---------+-------
 tech_db | 16393
(1 row) 

we can see value of oid for database tech_db is 16393 and in above screenshot we can find the same folder under base directory. Under it you can find number of files and now lets find the file related to our table employee

tech_db=# select relname,oid, relfilenode from pg_class where relname='employee';
 relname  |  oid  | relfilenode
----------+-------+-------------
 employee | 16394 |       16394
(1 row)

pick up the relfilenode from above output, you will be able to see same file under folder 16393

physical-location-of-datafile-in-postgresql






  • Share This:  
  •  Facebook
  •  Twitter
  •  Instagram
  •  Pin
  •  linkedin
  •  reddit
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

1 comment:

  1. James Zicrov4 July 2021 at 12:19

    This is an exclusive post about PostgreSQL and the use of foreign data wrapper actually overcomes and helps people solve the most complex problems and errors.

    SSIS postgresql read

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Author

Atikh Shaikh
View my complete profile

Categories

  • MongoDB (18)
  • Oracle 12c (30)
  • Oracle12cR2 New Feature (3)
  • PostgreSQL (21)
  • RMAN (10)
  • Snowflake (8)
  • mysql (23)
  • oracle (74)

Blog Archive

  • ►  2018 (38)
    • ►  November (25)
    • ►  December (13)
  • ►  2019 (33)
    • ►  January (15)
    • ►  February (6)
    • ►  March (2)
    • ►  April (5)
    • ►  May (5)
  • ▼  2020 (5)
    • ►  April (1)
    • ►  May (2)
    • ▼  July (2)
      • Physical location of datafiles in PostgreSQL
      • 12cR2 New Feature -sql prompt "history"
  • ►  2021 (8)
    • ►  June (3)
    • ►  July (3)
    • ►  August (1)
    • ►  December (1)
  • ►  2022 (33)
    • ►  May (3)
    • ►  June (10)
    • ►  July (3)
    • ►  August (4)
    • ►  September (8)
    • ►  October (3)
    • ►  November (2)
  • ►  2023 (14)
    • ►  February (1)
    • ►  April (5)
    • ►  May (2)
    • ►  June (1)
    • ►  September (1)
    • ►  October (1)
    • ►  December (3)
  • ►  2024 (5)
    • ►  January (2)
    • ►  March (3)
  • ►  2025 (7)
    • ►  March (1)
    • ►  April (3)
    • ►  May (2)
    • ►  August (1)
  • ►  2026 (1)
    • ►  January (1)

Popular Posts

  • PostgreSQL : How to describe table in psql
    For the DBA's using a conventional database such as oracle, they have a habit of using DESC or DESCRIBE but in PostgreSQL , it's in ...
  • ORA-29283: invalid file operation: unexpected "LFI" error (1509)[29437]
    I was trying to export the schema in my windows PC, it got stuck with below error    C:\Users\shaik\Videos\technodba exp>expdp userid...
  • ORACLE : Creating a new pluggable database using PDB$SEED
    As a database administrator, you might come across creating a pluggable database, here is the method to create a pluggable database (PDB), F...
  • Table Dropped in Oracle Database ? Worry not, we can recover it
    There are a couple of options we can use to recover dropped tables in 19c Oracle database version  Restore table from Recycle Bin (assume ...
  • Oracle : Starting with RMAN Commands
    In previous article we have discussed introduction to RMAN , Now will learn RMAN commands and taking backup of database and understanding i...

Labels

oracle Oracle 12c mysql PostgreSQL MongoDB oracle 19c Oracle23c oracle19c Orale PDB-CDB oracle12c python AWS Oracle ASM Virtualbox pluggable database storage engine

Pages

  • Disclaimer
  • Privacy Policy

Follow TechnoDBA

Copyright © Atikh's DBA blog | Powered by Blogger