标签: postgresql-15

Postgres 15. 模式公共权限被拒绝

无法以非超级用户身份在公共架构中创建表

postgres - 超级用户。

我做了什么:

ALTER SCHEMA public owner to postgres;  

CREATE USER admin WITH PASSWORD 'my-password';   

GRANT USAGE, CREATE ON SCHEMA public TO postgres;   
GRANT USAGE, CREATE ON SCHEMA public TO admin;    

CREATE DATABASE mydb;    
GRANT ALL ON DATABASE mydb TO admin;
Run Code Online (Sandbox Code Playgroud)

特权:

postgres=# \dn+
                          List of schemas
  Name  |  Owner   |  Access privileges   |      Description       
--------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres+| standard public schema
        |          | =UC/postgres        +| 
        |          | admin=UC/postgres    | 
(1 row)
Run Code Online (Sandbox Code Playgroud)

我得到了什么:

在此输入图像描述

如何在公共模式中创建表?

sql postgresql debian postgresql-15

51
推荐指数
1
解决办法
5万
查看次数

模板数据库“template1”具有排序规则版本,但无法确定实际的排序规则版本

我刚刚将 Postgres 从 12 升级到 15,但不断收到此错误: template database "template1" has a collation version, but no actual collation version could be determined

这是 Postgres 15 中的 template1 排序规则信息: 在此输入图像描述

有想法该怎么解决这个吗?如果需要更多信息,请告诉我。

谢谢!

更新:

以下是操作系统信息:
发行商 ID:Debian。
描述:Debian GNU/Linux 10(破坏者)。
发布:10。
代号:buster。

我有一个 Postgres docker 容器,所以我用它来升级:https ://github.com/tianon/docker-postgres-upgrade/tree/master/12-to-15

我没有更换机器或升级操作系统。以下是 PG 12 上的 template1 整理信息:

在此输入图像描述

更新2:

所以我做了一些挖掘,结果发现 en_US.utf8 排序规则在 Postgres 12 上的 pg_collat​​ion 表中不存在。但是在 Postgres 15 上,它确实存在于该表中,并且版本为 2.31:

在此输入图像描述

有没有什么办法解决这一问题?

database postgresql collation postgresql-12 postgresql-15

11
推荐指数
2
解决办法
7878
查看次数

为什么我的唯一索引在 Postgresql 中不起作用?

我创建了一个表来存储用户的休息日数据。之后,为多列设置唯一索引,但是当执行插入sql时,它再次重复数据

这是我的 DDL:

create table day_off_movements
(
    id                 bigserial
        primary key,
    user_id            bigint
        constraint fk_day_off_movements_user
            references users,
    proxy_user_id      bigint
        constraint fk_day_off_movements_proxy_users
            references users,
    reason             text,
    day_off_start_date timestamp with time zone,
    day_off_end_date   timestamp with time zone,
    used_days          bigint,
    created_at         timestamp with time zone,
    updated_at         timestamp with time zone
);
Run Code Online (Sandbox Code Playgroud)

指数:

create unique index idx_day_off_all
    on day_off_movements (user_id, proxy_user_id, day_off_start_date, day_off_end_date);
Run Code Online (Sandbox Code Playgroud)

控制查询:

SELECT user_id,proxy_user_id,day_off_end_date,day_off_start_date,count(*)
                 FROM public.day_off_movements t
GROUP BY user_id, proxy_user_id, day_off_end_date, day_off_start_date
Run Code Online (Sandbox Code Playgroud)

输出为 json:

[
  {
    "user_id": 961,
    "proxy_user_id": null,
    "day_off_end_date": …
Run Code Online (Sandbox Code Playgroud)

postgresql postgresql-15

3
推荐指数
2
解决办法
170
查看次数

连接到 PostgreSQL 时没有属性“执行”错误

我在 PC1 上安装了 postgres,并使用 PC2 连接到数据库。我修改了设置,以便本地网络可以访问 PC1 上的 postgres。

在 PC2 上我正在执行以下操作:

import pandas as pd, pyodbc
from sqlalchemy import create_engine
z1 = create_engine('postgresql://postgres:***@192.168.40.154:5432/myDB')
z2 = pd.read_sql(fr"""select * from public."myTable" """, z1)
Run Code Online (Sandbox Code Playgroud)

我收到错误:

File "C:\Program Files\Python311\Lib\site-packages\pandas\io\sql.py", line 1405, in execute
    return self.connectable.execution_options().execute(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'OptionEngine' object has no attribute 'execute'
Run Code Online (Sandbox Code Playgroud)

在 PC1 上运行相同的代码时,我没有收到错误。

我只是注意到它仅在从数据库读取时才会发生。如果我这样做,to_sql它就会起作用。似乎 PC2 上缺少,因为192.168.40.154:5432如果我使用而不是尝试localhost:5432,我会得到相同的错误。

编辑:以下修改有效,但不知道为什么。有人可以告诉我这可能是什么原因吗?

from sqlalchemy.sql import text
connection = connection = z1.connect()
stmt = text("SELECT * FROM public.myTable")
z2 …
Run Code Online (Sandbox Code Playgroud)

postgresql pandas python-3.11 postgresql-15

2
推荐指数
1
解决办法
3156
查看次数