postgresql 数据库在 OS X 上的位置?

发布于 2024-10-18 16:57:54 字数 461 浏览 2 评论 0原文

我确信这个问题已经得到解答,但我似乎找不到答案。

我使用 Homebrew (brew install postgresql) 安装了 postgresql,它安装到 /usr/local/Cellar/postgresql。根据我的说明,我这样做了:

If this is your first install, create a database with:
    initdb /usr/local/var/postgres

据我了解,initdb 创建了一个新的数据库集群。因此,当我执行上述操作时,数据库名称和数据库本身是“postgres”,还是所有 postgresql 数据库都需要的所有必要位?

实际的数据库最终存放在哪里?我是 postgresql 新手,正在寻找作为数据库的文件或二进制文件。 那么,数据库在哪里?当我创建一个新数据库时,它会去哪里?

I'm sure this has been answered but I cannot seem to find an answer.

I installed postgresql using Homebrew (brew install postgresql) which installed to /usr/local/Cellar/postgresql. Afterwords per the instructions I did this:

If this is your first install, create a database with:
    initdb /usr/local/var/postgres

As I understand it, initdb creates a new cluster of databases. So when I did the above is "postgres" the database name and the database itself or just all the necessary bits that all postgresql databases will need?

Where does the actual database end up living? I am new to postgresql and looking for a file or binary that is the database. So, where is the database, and when I create a new one where does it go?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

慕巷 2024-10-25 16:57:55

运行以下查询:

SHOW DATA_DIRECTORY;

Run the following query:

SHOW DATA_DIRECTORY;
伏妖词 2024-10-25 16:57:55

由于 Mac 中存在三种不同的库,因此开发人员通常对这三种情况感到困惑。但是,您可以在 Mac 计算机上使用两种方法之一找到您的 PostgreSQL 目录。

1.目录——绝对路径

1).将鼠标向上滚动到 Mac 屏幕的左上角

2)。单击菜单“开始”

3)。选择“转到文件夹...”

4)。输入路径

/Users/用户名/Library/Application Support/Postgres

请将“用户名”更改为您的名字,例如下面列出的“jack”。

/Users/jack/Library/Application Support/Postgres

5).选择“Go”按钮进入 Postgres 目录。

你最终会发现 Postgres。

2.一步步找到目录

1).将鼠标向上滚动到 Mac 屏幕的左上角。

2)。单击菜单“前往”。

3)。选择“库”按钮

4)。双击文件持有者“应用程序支持”。

5)。按照字母顺序查找“Postgres”。

干杯,

迈克

Since there are three different libraries in Mac, developers are usually confused with the three scenarios. However, you can find out your PostgreSQL directory with one of the two methods on the Mac Computer.

1. Directory--Absolute Path

1). Scroll up your mouse to the left top of Mac Screen

2). Click the menu "Go"

3). Select the "Go to Folder..."

4). Input the path

/Users/username/Library/Application Support/Postgres

Please change "username" to your name such as "jack" listed as follows.

/Users/jack/Library/Application Support/Postgres

5). Choose the button "Go" to the directory of Postgres.

You will eventually find out Postgres.

2. Find the directory step by step

1). Scroll up your mouse to the left top of Mac Screen.

2). Click the menu "Go".

3). Select the button "Library"

4). Double click the file holder "Application Support".

5). Find out "Postgres" according to the alphabetic order.

Cheers,

Mike

冰火雁神 2024-10-25 16:57:55

系统:MAC OS X 10.9.5
现在(版本 9.4)位于名为 /Library/PostgreSQL 的目录下
如果你去那里,打开名为 ver. 的文件夹。你的PG,然后进入文件夹data你会找到你的DB。这实际上是一组很多很多不同的二进制文件和文本文件(其中大多数都以长数字命名,例如“92891”等等......
请注意,要打开 data 文件夹,您必须打开其属性(单击鼠标右键并选择“获取信息”)并允许您读取该文件夹。
如果您不熟悉这一点,我不建议您打开 RW 权限,因为任何最小的更改都会影响您的整个数据库,这将是悲伤的..

祝您好运!

System: MAC OS X 10.9.5
Now (ver. 9.4) this is under the dir called /Library/PostgreSQL
If you go there, open the folder named as the ver. of your PG and then go to the folder data you will find your DB. This is really a set of many-many-many different both binary and text files (most of those are named with long numbers like "92891" or so...
Note, to open the data folder you have to open its properties (right mouse click and select "Get info") and allow you to read this folder.
I wdn't suggest you to open the RW permissions if you aren't familiar with this as any smallest change can affect you whole DB which is would be sad..

Good luck!

影子的影子 2024-10-25 16:57:55

就我而言(不是自制程序),数据位置可以在此文件 /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist 中找到

   <array>
            <string>/Users/me/bin/postgres/bin/postmaster</string>
            <string>-D/Users/me/data/postgres</string>
   </array>

In my case (not homebrew) the data location is found in this file /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist

   <array>
            <string>/Users/me/bin/postgres/bin/postmaster</string>
            <string>-D/Users/me/data/postgres</string>
   </array>
╰沐子 2024-10-25 16:57:55

不同安装程序的当前行为记录在 https://wiki.postgresql.org/ wiki/Installers/Mac_OS_X#Known_Installers。正如上面有人评论的那样,Homebrew 不会将数据放在 /Library 下。

The current behavior of the different installers is documented at https://wiki.postgresql.org/wiki/Installers/Mac_OS_X#Known_Installers. Homebrew does not, as someone commented above, put the data under /Library.

时光病人 2024-10-25 16:57:55

使用SHOW DATA_DIRECTORY;,位置是

/opt/homebrew/var/postgresql@14

Using SHOW DATA_DIRECTORY;, the location is

/opt/homebrew/var/postgresql@14
我爱人 2024-10-25 16:57:54

initdb 只是设置目录结构,这样需要创建新的数据库。要创建数据库,请使用 createdb

概要
createdb [ 选项... ] [ 数据库名称 ] [ 描述 ]

描述
createdb 创建一个新的 PostgreSQL 数据库。

通常,执行该命令的数据库用户成为所有者
新数据库的。但是可以通过 -O 选项指定不同的所有者,
执行用户是否具有适当的权限。

createdb 是 SQL 命令 CREATE DATABASE [create_database(7)] 的包装器。
通过此实用程序创建数据库与通过此实用程序创建数据库之间没有任何实际区别
通过其他方式访问服务器。

initdb 有点像在硬盘上创建新的文件系统:首先创建文件系统 (initdb),然后创建文件和目录 (创建b)。

创建数据库后,实际的数据库文件将位于 /usr/local/var/postgres 下。因此,只需创建一个数据库,然后查看 /usr/local/var/postgres 下有哪些新增内容或更改。没有单个“dbname.db”文件或类似的文件,每个数据库都是其名称仅对数据库服务器有意义的文件的集合。

initdb just sets up the directory structure and such that is needed to create new databases. To create a database, use createdb:

SYNOPSIS
createdb [ option... ] [ dbname ] [ description ]

DESCRIPTION
createdb creates a new PostgreSQL database.

Normally, the database user who executes this command becomes the owner
of the new database. However a different owner can be specified via the -O option,
if the executing user has appropriate privileges.

createdb is a wrapper around the SQL command CREATE DATABASE [create_database(7)].
There is no effective difference between creating databases via this utility and
via other methods for accessing the server.

initdb is sort of like creating a new file system on a hard disk: first you create the file system (initdb), then you create a files and directories (createdb).

The actual database files will be under /usr/local/var/postgres after you create the database. So, just create a database and then see what's new or changed under /usr/local/var/postgres. There isn't a single "dbname.db" file or anything like that, each database is a collection of files with names that are only meaningful to the database server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文