为什么我无法使用创建的用户连接到我的数据库,尽管拥有所有权限?
为什么我无法使用创建的用户连接到我的数据库,尽管拥有所有权限?
昨天,我发布了一篇帖子来修复我的数据库代码问题,我需要修复一些拼写错误,现在已经解决了。唯一的问题是我只能以默认的postgres用户连接到我的数据库,而我想连接到我在文件中创建的用户。我在下面展示了状态:
CREATE DATABASE equipment; CREATE USER equipment WITH ENCRYPTED PASSWORD 'testing'; GRANT ALL PRIVILEGES ON DATABASE "equipment" to equipment; GRANT USAGE ON SCHEMA public TO equipment; GRANT CONNECT ON DATABASE equipment TO equipment; ALTER USER equipment WITH SUPERUSER; \c equipment equipment; CREATE TABLE material ( material_id INTEGER NOT NULL, name VARCHAR(128) NOT NULL, description VARCHAR(256) NOT NULL, tensile_strength INTEGER NOT NULL, PRIMARY KEY ( material_id ) ); CREATE TABLE costs ( cost_id INTEGER NOT NULL, material_id INTEGER NOT NULL, price DECIMAL(10,2) NOT NULL, CONSTRAINT fk_material_id FOREIGN KEY (material_id) REFERENCES material(material_id) PRIMARY KEY ( cost_id ) ); CREATE TABLE usages ( usage_id INTEGER NOT NULL, cost_id INTEGER NOT NULL, purpose VARCHAR(256) NOT NULL, location_to_purchase VARCHAR(256) NOT NULL, CONSTRAINT fk_cost_id FOREIGN KEY (cost_id) REFERENCES costs(cost_id) PRIMARY KEY ( usage_id ) ); GRANT ALL PRIVILEGES ON material, costs, usages TO equipment;
编辑后的pg_hba.conf文件可以连接到equipment用户;
包含更改的配置文件内容:
# Database administrative login by Unix domain socket local all postgres peer local all equipment md5
运行后的输出如下:
GRANT GRANT GRANT ALTER ROLE Password for user equipment:
输入“testing”可以让我进入(是否有自动输入的方式?)