Where does PostgreSQL store the database?

后端 未结 13 1738
忘了有多久
忘了有多久 2020-11-27 09:14

Where are the files for a PostgreSQL database stored?

13条回答
  •  感情败类
    2020-11-27 09:49

    Postgres stores data in files in its data directory. Follow the steps below to go to a database and its files:

    The database corresponding to a postgresql table file is a directory. The location of the entire data directory can be obtained by running SHOW data_directory. in a UNIX like OS (eg: Mac) /Library/PostgreSQL/9.4/data Go inside the base folder in the data directory which has all the database folders: /Library/PostgreSQL/9.4/data/base

    Find the database folder name by running (Gives an integer. This is the database folder name):

    SELECT oid from pg_database WHERE datname = ;
    

    Find the table file name by running (Gives an integer. This is the file name):

    SELECT relname, relfilenode FROM pg_class WHERE relname = ; 
    

    This is a binary file. File details such as size and creation date time can be obtained as usual. For more info read this SO thread

提交回复
热议问题