Open dbgp opened 11 months ago
lealone 这个 database 的默认用户是 root,密码是空。 POSTGRES 这个 database 的默认用户是 postgres,密码也是 postgres。
在 psql 中连 lealone 这个 database,因为 psql 不支持空密码所以连不上,需要先在 lealone 的客户端执行 alter user root set password 'root';
在 psql 中可以连 POSTGRES 这个 database,如果不指定 -d 这个参数,默认数据库就是 POSTGRES。
每个 database 都有自己的独立 user,不同 database 里的 user 是不能跨库访问的,连不同 database 只能用它的 user。比如 lealone 这个数据库就没有 postgres 这个 user,所以不能用 postgres 这个用户连。
使用postgres用户可以连接到postgres数据库。
应该是版本不一致导致的?连接后由提示—— lealone里的pg版本是8.2.23,然后安装的版本是 16.1 (后面执行语法的报错是非是因为版本不一致导致的?)
➜ ~ psql -U postgres -h localhost -p 5432
Password for user postgres:
psql (16.1, server 8.2.23)
WARNING: psql major version 16, server major version 8.2.
Some psql features might not work.
Type "help" for help.
执行 \l
显示数据库时,server端报错
ERROR 21:37:06.905
org.lealone.common.exceptions.JdbcSQLException: Function "ARRAY_TO_STRING" not found; SQL statement:
SELECT
d.datname as "Name",
pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
'libc' AS "Locale Provider",
d.datcollate as "Collate",
d.datctype as "Ctype",
NULL as "ICU Locale",
NULL as "ICU Rules",
pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
FROM pg_catalog.pg_database d
ORDER BY 1 [90022-0]
at org.lealone.common.exceptions.DbException.getJdbcSQLException(DbException.java:342) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.common.exceptions.DbException.get(DbException.java:173) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.common.exceptions.DbException.get(DbException.java:150) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readJavaFunction(SQLParserBase.java:2269) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readFunction(SQLParserBase.java:2313) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readTermObjectDot(SQLParserBase.java:2530) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readTerm(SQLParserBase.java:2646) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readFactor(SQLParserBase.java:2183) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readSum(SQLParserBase.java:2170) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readConcat(SQLParserBase.java:2143) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readCondition(SQLParserBase.java:2007) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readAnd(SQLParserBase.java:1988) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.readExpression(SQLParserBase.java:1980) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parseSelectSimpleSelectPart(SQLParserBase.java:1707) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parseSelectSimple(SQLParserBase.java:1530) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parseSelectSub(SQLParserBase.java:1507) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parseSelectUnion(SQLParserBase.java:1477) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parseSelect(SQLParserBase.java:1465) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parseStatement(SQLParserBase.java:455) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parse(SQLParserBase.java:327) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parse(SQLParserBase.java:285) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.sql.SQLParserBase.parse(SQLParserBase.java:186) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.db.session.ServerSession.prepareStatement(ServerSession.java:426) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.db.session.ServerSession.prepareStatement(ServerSession.java:413) ~[lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.plugins.postgresql.server.handler.CommandPacketHandler.query(CommandPacketHandler.java:209) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.plugins.postgresql.server.handler.CommandPacketHandler.handle(CommandPacketHandler.java:64) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.plugins.postgresql.server.handler.PacketHandler.handle(PacketHandler.java:55) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.plugins.postgresql.server.PgServerConnection.handlePacket(PgServerConnection.java:166) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.plugins.postgresql.server.PgTask.run(PgTask.java:23) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.server.scheduler.SessionInfo.runTask(SessionInfo.java:104) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.server.scheduler.SessionInfo.submitTask(SessionInfo.java:68) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.plugins.postgresql.server.PgServerConnection.handle(PgServerConnection.java:147) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.net.nio.NioEventLoop.read(NioEventLoop.java:275) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.net.nio.NioEventLoop.handleSelectedKeys(NioEventLoop.java:492) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.net.NetScheduler.runEventLoop(NetScheduler.java:62) [lealone-6.0.0-SNAPSHOT.jar:?]
at org.lealone.server.scheduler.GlobalScheduler.run(GlobalScheduler.java:75) [lealone-6.0.0-SNAPSHOT.jar:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
ERROR 21:38:38.517
客户端报错——
postgres-> \l
ERROR: Function "ARRAY_TO_STRING" not found; SQL statement:
SELECT
d.datname as "Name",
pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
'libc' AS "Locale Provider",
d.datcollate as "Collate",
d.datctype as "Ctype",
NULL as "ICU Locale",
NULL as "ICU Rules",
pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
FROM pg_catalog.pg_database d
ORDER BY 1 [90022-0]
DETAIL: org.lealone.common.exceptions.JdbcSQLException: Function "ARRAY_TO_STRING" not found; SQL statement:
SELECT
d.datname as "Name",
pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
'libc' AS "Locale Provider",
d.datcollate as "Collate",
d.datctype as "Ctype",
NULL as "ICU Locale",
NULL as "ICU Rules",
pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
FROM pg_catalog.pg_database d
ORDER BY 1 [90022-0]
使用 \i path/to/schema.sql
执行 sql文件 时也会报错。语法相关的错误。
目前对 postgresql 的兼容还在不断完善,ARRAY_TO_STRING 这个函数没有实现。
专用的语法应该都还需要一些兼容工作。\dt
中用到的 PG_TABLE_IS_VISIBLE 函数也找不到。
postgres=> \dt
ERROR: Function "PG_TABLE_IS_VISIBLE" not found; SQL statement:
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','p','')
AND n.nspname <> 'pg_catalog'
AND n.nspname !~ '^pg_toast'
AND n.nspname <> 'information_schema'
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2 [90022-0]
DETAIL: org.lealone.common.exceptions.JdbcSQLException: Function "PG_TABLE_IS_VISIBLE" not found; SQL statement:
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','p','')
AND n.nspname <> 'pg_catalog'
AND n.nspname !~ '^pg_toast'
AND n.nspname <> 'information_schema'
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2 [90022-0]
请教下这个创建表的sql报错是因为哪些部分没有兼容?‘ TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()’ 这个语法?
CREATE TABLE IF NOT EXISTS users (
user_id VARCHAR(36) NOT NULL PRIMARY KEY,
full_name VARCHAR(1024) NOT NULL,
identity_number VARCHAR(11) NOT NULL UNIQUE,
avatar_url VARCHAR(1024) NOT NULL,
access_token VARCHAR(512) NOT NULL DEFAULT '',
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
TIMESTAMP WITH[*] TIME ZONE NOT NULL DEFAULT NOW()
带有 *[]** 的地方就是语法错误的起始位置。
TIMESTAMP 类型目前还不支持 WITH TIME ZONE。
目前 lealone 6 内置的 mongodb、mysql、postgresql 插件,当前是优先做 mongodb 插件,兼容度更高,其次是 mysql,postgresql 兼容的优先级低一些,接下来3个月会陆续完善这3个插件。
背景: 本地没有按照pq数据库,实验的项目采用了pg数据库。想使用lealone做为替代。
现象: 启动lealone之后,使用psql做为postgresql的命令行客户端进行连接,连接后提示输入。提示对应的数据库不存在。
需求: 如何创建pg使用的数据库?
所有数据时共享的话,利用root登陆lealone,直接创建对应的db,user这些信息?——不确定这样的理解是否正确。
查看有默认的 POSTGRES数据库,
使用postgres账户连接时,会提示密码不正确。