标签: postgresql-12

将 postgresql 本地复制到远程数据库(均带有密码)-错误:无法识别选项“locale”

使用 Postgres 12 / Windows 10。

尝试使用以下命令将远程数据库复制到 localhost:

pg_dump -C -h remotehost -p 5432 -U postgres remotedb | psql -h localhost -p 5432 -U postgres localdb

CMD 请求密码 2x。

Password for user postgres: Password:

我先输入 localhost,按 ENTER,然后输入 remotehost 并再次按 ENTER。

这是我得到的错误回报:

SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
ERROR:  option "locale" not recognized
LINE 1: ...ting" WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE = '...
                                                             ^
ERROR:  database "remotedb" does not exist
\connect: …
Run Code Online (Sandbox Code Playgroud)

postgresql pg-dump psql postgresql-12 postgresql-13

7
推荐指数
2
解决办法
1470
查看次数

插入整数列时不要静默舍入浮点输入

我有一张像:

CREATE TABLE foo(bar int)
Run Code Online (Sandbox Code Playgroud)

我有一个将值插入该表的脚本:

INSERT INTO foo(bar)
VALUES (1), (2), (3.2)
Run Code Online (Sandbox Code Playgroud)

浮点值被静默四舍五入以适合数据类型:

> SELECT * FROM foo;
 bar
-----
   1
   2
   3
(3 rows)
Run Code Online (Sandbox Code Playgroud)

Postgres 是否有任何内置功能可以防止这种情况发生,而是引发错误?(甚至是警告?)

postgresql postgresql-12

6
推荐指数
1
解决办法
70
查看次数

容器上的 PostgreSQL 抛出错误 chmod: /var/lib/postgresql/data: Operation not allowed

我尝试在 docker 和我创建的以下文件上运行 Postgres 12。我不明白我在哪里犯了错误以及 PostgreSQL 文件权限的问题。

Dockerfile:

FROM postgres:12.0-alpine
USER root
RUN chmod 0775 /var/lib/postgresql
RUN chown postgres /var/lib/postgresql
USER postgres
# RUN chmod 0775 /var/lib/postgresql
# RUN chown postgres /var/lib/postgresql
RUN ls -l /var/lib/postgresql
# RUN pgctl -D /usr/local/psql/data initdb &&\
RUN initdb -D /var/lib/postgresql/data &&\
    echo "host all  all    0.0.0.0/0  md5" >> /var/lib/postgresql/data/pg_hba.conf && \
    echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf && \
    pg_ctl start && \
    psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'test'" …
Run Code Online (Sandbox Code Playgroud)

postgresql database-administration dockerfile docker-compose postgresql-12

5
推荐指数
0
解决办法
884
查看次数

Knex:获取连接超时

从今天开始,当我尝试使用 knex.js 在本地连接到 postgres 数据库 (v 12) 时,出现以下错误。

Unhandled rejection TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
Run Code Online (Sandbox Code Playgroud)

这种情况发生在我已经工作了一年的项目上,没有出现任何问题。为了解决这个问题,我创建了一个包含一张表的新数据库。运行以下代码行时,我收到相同的错误:

const knex = require('knex');

const db = knex({
  client: 'pg',
  connection: 'postgresql://postgres:postgres@localhost/a_test',
  pool: {
    min: 0,
    max: 10,
  },
});

db.from('test_table')
  .select(['id'])
  .then(r => {
    console.log(r);
  });

Run Code Online (Sandbox Code Playgroud)

我不知道是什么原因造成的。几周前,一切都运行良好,在此期间我没有改变任何东西。我使用postgresapp在本地运行 postgres ,当我使用 连接到数据库时psql,一切正常。我有什么想法可以解决这个问题吗?

postgresql node.js knex.js postgresql-12

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

Postgresql 12 - 排序规则在 Windows / Linux 上不起作用

我已经在 Wnindows 和 Linux CentOS 8 上安装了 Postgresql 12。

对于我的项目,我需要创建自己的 ICU 排序规则并将其应用于所有字符列(在列创建中或按请求排序 = 首选)。

在此之前,我尝试制作一个简单的测试用例来检查它是否按预期工作......但事实并非如此。

包含一些数字和字母数据的简单表格

DROP TABLE IF EXISTS TBL;
CREATE TABLE TBL ( TEXT1 CHARACTER(5), TEXT2 CHARACTER(5) );
INSERT INTO TBL VALUES
 ('aaaaa', 'aaaaa')
,('aaaaa', '00000')
,('aaaaa', 'bbbbb')
,('aaaaa', '11111')

,('bbbbb', '22222')
,('00000', '22222')
,('ccccc', '22222')
,('11111', '22222');
Run Code Online (Sandbox Code Playgroud)

官方文档中拉丁字符后的数字排序规则 https://www.postgresql.org/docs/12/collat​​ion.html

CREATE COLLATION digitslast (provider = icu, locale = 'en-u-kr-latn-digit');
CREATE COLLATION digitslast (provider = icu, locale = 'en@colReorder=latn-digit');
    Sort digits after Latin letters. (The default is digits before …
Run Code Online (Sandbox Code Playgroud)

postgresql collation icu postgresql-12

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

Mikro-orm 错误:用户“postgres”的密码验证失败

我正在尝试按照这个React GraphQL TypeScript 教程编写代码

该项目使用 MikroOrm 与 PostgreSQL 数据库进行通信。我在我的 Ubuntu 18.04 上安装了 PostgreSQL(12.4),创建了一个“postgres”用户,我可以登录该用户并正常运行psql。但是,当我开始使用(视频时间戳)之mikro-orm类的命令,出现以下错误:npx mikro-orm migration:create

error: password authentication failed for user "postgres"
    at Parser.parseErrorMessage (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:357:11)
    at Parser.handlePacket (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:186:21)
    at Parser.parse (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:101:30)
    at Socket.<anonymous> (/home/<username>/newstack/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  length: 104,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined, …
Run Code Online (Sandbox Code Playgroud)

postgresql ubuntu-18.04 mikro-orm postgresql-12

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

使用节点获取特定 Postgres 数据库中的所有表?

我需要使用 node.js 获取特定 Postgres 数据库中的所有表。但没有找到任何方法来实现这一目标。有没有办法得到它?

例如,假设我有一个名为“TestDatabase”的数据库,它包含 4 个表(假设它可以有更少或更多)人、公司、衣服、动物。我需要使用 node.js 获取所有这些的名称。

我还使用 node-postgres ('pg') 连接数据库。

postgresql node.js node-postgres postgresql-12

5
推荐指数
0
解决办法
149
查看次数

brew postgresql-upgrade-database 迁移和升级数据失败

我刚刚坐下来工作,忘记了我已经在 2020 \xe2\x80\x93 中升级了brew,所以我当然遇到了 postgresql 问题。

\n

我的最后一个版本是 12.x。现在我已经安装了13.1:

\n
$ brew info postgres                                \nWarning: Treating postgres as a formula. For the cask, use homebrew/cask/postgres\npostgresql: stable 13.1 (bottled), HEAD\nObject-relational database system\nhttps://www.postgresql.org/\n/usr/local/Cellar/postgresql/13.1 (3,217 files, 42.6MB) *\n  Poured from bottle on 2020-12-26 at 14:36:54\nFrom: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql.rb\nLicense: PostgreSQL\n==> Dependencies\nBuild: pkg-config \xe2\x9c\x94\nRequired: icu4c \xe2\x9c\x94, krb5 \xe2\x9c\x94, openssl@1.1 \xe2\x9c\x94, readline \xe2\x9c\x94\n==> Options\n--HEAD\n    Install HEAD version\n==> Caveats\nTo migrate existing data from a previous major version of PostgreSQL run:\n  brew postgresql-upgrade-database\n\nThis formula has created a default database cluster …
Run Code Online (Sandbox Code Playgroud)

postgresql macos homebrew postgresql-12

5
推荐指数
0
解决办法
1819
查看次数

如何在关闭后启动 pg_cron 扩展

必须终止 pg_cron 运行的进程。然而,在执行该操作后 pg_cron 扩展停止了。以下是来自服务器的日志:

2021-04-29 12:55:40.712 UTC [535529] LOG:  pg_cron scheduler shutting down
Run Code Online (Sandbox Code Playgroud)

现在,没有作业正在运行。如何在不重新启动 PostgreSQL 服务器的情况下重新启动扩展。

database unix postgresql postgresql-extensions postgresql-12

5
推荐指数
0
解决办法
638
查看次数

从 Postgres 13 开始,哈希索引对于精确文本匹配查询来说是最佳的吗?

示例(假)情况:当将专门查询包含电子邮件(文本类型)的列以获取精确的字符串匹配时,对该列进行索引。

SELECT * FROM mytable WHERE email = 'test@test.com'
Run Code Online (Sandbox Code Playgroud)

在这些情况下,哈希索引是否比 B-TREE 有优势且没有缺点?

它们对插入/更新性能的影响是否不同?

(编辑:并且从未按此列排序)

postgresql postgresql-12 postgresql-13

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