简体   繁体   English

PostgreSQL和Docker:需要哪个目录来保留数据

[英]postgresql and docker: which directory is needed to persist data

In postgresql which are the directories we need to persist in general so that i can use the same data again even i rebuild postgresql ,这是我们通常需要保留的目录,以便即使我重新构建也可以再次使用相同的数据

Like: 喜欢:

I know the main directory: 我知道主目录:

/var/lib/postgres or  /var/lib/postgres/data (small confusion, which one)

and any other like the logs etc 和其他类似日志等

You can define the PGDATA environment variable in your docker container to specify where postgres will save its database files. 您可以在docker容器中定义PGDATA环境变量,以指定postgres将其数据库文件保存在何处。

From the documentation of the official postgres Docker image: 从官方postgres Docker映像的文档中:

  • PGDATA: PGD​​ATA:

    This optional variable can be used to define another location - like a subdirectory - for the database files. 此可选变量可用于为数据库文件定义另一个位置,例如子目录。 The default is /var/lib/postgresql/data, but if the data volume you're using is a filesystem mountpoint (like with GCE persistent disks), Postgres initdb recommends a subdirectory (for example /var/lib/postgresql/data/pgdata ) be created to contain the data. 默认值为/ var / lib / postgresql / data,但是如果您使用的数据量是文件系统挂载点(例如GCE永久磁盘),则Postgres initdb建议使用一个子目录(例如/ var / lib / postgresql / data / pgdata)创建为包含数据。

Additionally from the postgres documentation transaction log files are also written to PGDATA : 此外, postgres文档中的事务日志文件也被写入PGDATA

By default the transaction log is stored in a subdirectory of the main Postgres data folder (PGDATA). 默认情况下,事务日志存储在Postgres主数据文件夹(PGDATA)的子目录中。

So by default the postgres image will write database files to /var/lib/postgresql/data 因此,默认情况下, postgres映像会将数据库文件写入/var/lib/postgresql/data

To answer your question it should be sufficient to bind mount a directory to /var/lib/postgresql/data inside of your postgres container. 要回答您的问题,将安装目录绑定到postgres容器内的/var/lib/postgresql/data应该足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM