简体   繁体   English

无法以postgres用户身份连接到postgresql

[英]Cannot connect to postgresql as postgres user

I am using mac OS X 10.5.8. 我正在使用Mac OS X 10.5.8。 I installed PostgreSQL 9.1 (using a mac dmg driver) in order to build a database with python (using sqlalchemy and psycopg2). 我安装了PostgreSQL 9.1(使用mac dmg驱动程序)以便使用python(使用sqlalchemy和psycopg2)构建数据库。

When I first tried to connect to PostgreSQL via sqlalchemy I could not find a username:password combination that would allow me to create an engine and connect. 当我第一次尝试通过sqlalchemy连接到PostgreSQL时,找不到用户名:密码组合,该组合允许我创建引擎并进行连接。 I tried logging in as a superuser with postgres (which supposedly does not require a password), but that didn't work. 我尝试以超级用户身份使用postgres(该密码不需要密码)登录,但这没有用。 I run into the same problems if I try connecting using the SQL shell (it requires me to enter a password even if I pick postgres as the user) or on the command line using su postgres. 如果尝试使用SQL Shell(即使我以postgres为用户,也需要输入密码)进行连接,或者在命令行中使用su postgres进行连接,都会遇到相同的问题。

Searching on Google for similar problems, it seems that this has something to do with the pg_hba.conf file, but I cannot locate it. 在Google上搜索类似的问题,似乎这与pg_hba.conf文件有关,但是我找不到它。 Somebody pointed out that on mac it should be in Library/PostgreSQL/9.1/data folder, but I do not have rights to access this folder. 有人指出,在Mac上它应该位于Library / PostgreSQL / 9.1 / data文件夹中,但是我没有访问此文件夹的权限。 Typing locate pg_hba.conf in the command line returns nothing. 在命令行中键入locate pg_hba.conf不会返回任何内容。 If I understand correctly (and I'm sure I don't as I've never used a database server before and I am no UNIX expert), the server is not recognizing me as the administrator, or superuser. 如果我理解正确(并且我确定自己没有用过,因为我以前从未使用过数据库服务器,而且我不是UNIX专家),则该服务器未将我识别为管理员或超级用户。

Is there something extremely obvious I do not know about initializing PostgreSQL (I searched through the documentation for "getting started" and post-installation configuration, but did not find anything that would obviously be related to this issue)? 关于初始化PostgreSQL,是否有我不知道的极其明显的东西(我在文档中搜索了“入门”和安装后配置,但没有发现与该问题明显相关的任何东西)? Could this be a problem with the installation of PostgreSQL? PostgreSQL的安装是否可能有问题? Might I have to change something in my environment? 我可能需要更改环境中的某些内容吗?

You need to switch to system account postgres. 您需要切换到系统帐户postgres。 Usually this is done using su - postgres . 通常,这是使用su - postgres If that doesn't work - I can't help as it looks like operating system level issue. 如果这不起作用-就像操作系统级别的问题一样,我无能为力。

When you'll be on postgres system account, you can edit pg_hba.conf, and, usually, you will be able to connect to pg, without password, using just plain psql . 使用postgres系统帐户时,您可以编辑pg_hba.conf,并且通常,仅使用简单的psql即可无需密码即可连接到pg。

On some systems, instead of using su , people use sudo , in which case you can try sudo su - postgres . 在某些系统上,人们使用sudo而不是使用su ,在这种情况下,您可以尝试sudo su - postgres

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

相关问题 Mac OSX上的PostgreSQL-无法以postgres用户身份登录 - PostgreSQL on Mac OSX - cannot log in as postgres user 使用最新版本的 Postgresql psql 客户端工具时无法连接到 Postgres 服务器 - Cannot connect to Postgres server when using latest version of Postgresql psql client tool Postgresql macports无法连接问题 - Postgresql macports cannot connect problem 无法使用C ++连接到PostgreSQL - Cannot connect to PostgreSQL using C++ 无法连接到通过 brew 服务运行的 Postgres 服务器 - Cannot connect to Postgres server running through brew services 无法连接到template1:​​致命:角色“ _postgres”不存在 - cannot connect to template1: FATAL: role “_postgres” does not exist postgresql无法登录到postgres管理员用户,并且将auth设置为trust并没有帮助(MacOS) - postgresql unable to login to postgres admin user and setting auth to trust didn't help (MacOS) 如何在mac os x 10.8.2上重置postgresql 9.2默认用户(通常是'postgres')密码? - How do I reset the postgresql 9.2 default user (usually 'postgres') password on mac os x 10.8.2? 如何访问PostgreSQL pg_log文件夹而不是postgres用户并遇到权限问题? - How to access PostgreSQL pg_log folder without being the postgres user and running into permission issues? 尝试使用Qt连接到Postgres - Trying to connect to Postgres with Qt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM