OS X 上 postgresql 数据库的位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5052907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Location of postgresql database on OS X?
提问by crobison
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:
我使用 Homebrew (brew install postgresql) 安装了 postgresql,它安装到 /usr/local/Cellar/postgresql。按照我做的说明后记:
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?
据我了解,initdb 创建了一个新的数据库集群。因此,当我执行上述操作时,“postgres”是数据库名称和数据库本身,还是所有 postgresql 数据库都需要的所有必要位?
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?
实际的数据库最终在哪里?我是 postgresql 的新手,正在寻找作为数据库的文件或二进制文件。 那么,数据库在哪里,当我创建一个新的数据库时它会去哪里?
回答by mu is too short
initdb
just sets up the directory structure and such that is needed to create new databases. To create a database, use createdb
:
initdb
只需设置创建新数据库所需的目录结构即可。要创建数据库,请使用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.
概要
createdb [ 选项... ] [ dbname ] [ 描述 ]描述
createdb 创建一个新的 PostgreSQL 数据库。通常,执行此命令的数据库用户将成为新数据库的所有者。但是,如果执行用户具有适当的权限,则可以通过 -O 选项指定不同的所有者。
createdb 是 SQL 命令 CREATE DATABASE [create_database(7)] 的包装器。通过此实用程序创建数据库与通过其他访问服务器的方法创建数据库之间没有实际区别。
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
).
initdb
有点像在硬盘上创建一个新的文件系统:首先创建文件系统 ( initdb
),然后创建文件和目录 ( 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.
/usr/local/var/postgres
创建数据库后,实际的数据库文件将在下面。因此,只需创建一个数据库,然后查看/usr/local/var/postgres
. 没有一个单一的“dbname.db”文件或类似的东西,每个数据库都是一个文件的集合,这些文件的名字只对数据库服务器有意义。
回答by AbuNassar
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
.
不同安装程序的当前行为记录在https://wiki.postgresql.org/wiki/Installers/Mac_OS_X#Known_Installers。正如上面有人评论的那样,Homebrew 不会将数据放在/Library
.
回答by Arsenii
System: MAC OS X 10.9.5Now (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..
系统:MAC OS X 10.9.5Now (ver. 9.4) 这是在名为的目录下/Library/PostgreSQL
如果你去那里,打开名为 ver. 的文件夹。PG,然后转到data
您将找到您的数据库的文件夹。这实际上是一组多对多不同的二进制文件和文本文件(大多数文件都以长数字命名,例如“ 92891
”等...注意,要打开data
文件夹,您必须打开其属性(鼠标右键单击)并选择“获取信息”)并允许您阅读此文件夹。如果您不熟悉这一点,我不建议您打开 RW 权限,因为任何最小的更改都会影响您整个数据库,这将是可悲的。
Good luck!
祝你好运!
回答by Matthias M
In my case (not homebrew) the data location is found in this file /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist
在我的情况下(不是自制软件),数据位置在这个文件中 /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>
回答by Mike Chen
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.
由于 Mac 中存在三个不同的库,因此开发人员通常会对这三种场景感到困惑。但是,您可以在 Mac 计算机上使用两种方法之一找到您的 PostgreSQL 目录。
1. Directory--Absolute Path
1.目录--绝对路径
1). Scroll up your mouse to the left top of Mac Screen
1)。将鼠标向上滚动到 Mac 屏幕的左上角
2). Click the menu "Go"
2)。点击菜单“前往”
3). Select the "Go to Folder..."
3)。选择“转到文件夹...”
4). Input the path
4)。输入路径
/Users/username/Library/Application Support/Postgres
/用户/用户名/库/应用程序支持/Postgres
Please change "username" to your name such as "Hyman" listed as follows.
请将“用户名”更改为您的姓名,例如“Hyman”,如下所示。
/Users/Hyman/Library/Application Support/Postgres
/Users/Hyman/Library/Application Support/Postgres
5). Choose the button "Go" to the directory of Postgres.
5)。选择按钮“Go”到 Postgres 的目录。
You will eventually find out Postgres.
你最终会发现 Postgres。
2. Find the directory step by step
2.一步一步找到目录
1). Scroll up your mouse to the left top of Mac Screen.
1)。将鼠标向上滚动到 Mac 屏幕的左上角。
2). Click the menu "Go".
2)。点击菜单“前往”。
3). Select the button "Library"
3)。选择按钮“库”
4). Double click the file holder "Application Support".
4)。双击文件持有人“应用程序支持”。
5). Find out "Postgres" according to the alphabetic order.
5)。根据字母顺序找出“Postgres”。
Cheers,
干杯,
Mike
麦克风