简体   繁体   English

Postgresql与Npgsql“的关系 <tablename> 不存在。“只发生在Win 7上

[英]Postgresql with Npgsql “relation <tablename> does not exist.” Only occurring on Win 7

I'm running into a very strange bug when using Postgresql using the Npgsql (2.0.11 and 2.0.11.94) DLL in .NET 3.5. 在.NET 3.5中使用Npgsql(2.0.11和2.0.11.94)DLL使用Postgresql时,我遇到了一个非常奇怪的错误。

I've created a program that will run these two queries (these are copied directly from the programs output): 我创建了一个程序来运行这两个查询(这些查询直接从程序输出中复制):

INSERT INTO "db_events" VALUES ('2','1','2','1', to_timestamp('2012/08/27 10:22:43', 'YYYY/MM/DD HH24:MI:SS'),'2012', '8', '27', '10', '22', '43', '35' );

INSERT INTO "db_events_counts" VALUES ('1','2', '0', '1', '0', '1' );

This program will run perfectly fine on Windows XP x86 with both postgres 8.4.12 and 9.0.9, and will enter the data into the tables as it should. 这个程序将在Windows XP x86上完美运行,同时具有postdres 8.4.12和9.0.9,并将数据输入到表中。

However, when running the exact same program on Windows 7 with a database that has been set up in an identical way to the Windows XP data base, I run into the error: 但是,当在Windows 7上运行完全相同的程序时,如果数据库的设置方式与Windows XP数据库完全相同,则会遇到错误:

ERROR: 42P01: relation "db_events" does not exist

I have read that this error is because postgres is forcing table names to lowercase, which is fine since they are already. 我已经读过这个错误是因为postgres强制表名为小写,这很好,因为它们已经存在。 Or that a table created with quotes has to be referenced with quotes, which is also fine since I am using quotes. 或者用引号创建的表必须用引号引用,这也很好,因为我使用引号。

In the windows 7 database, if i copy and paste these two queries into pgadmin, they work fine, no errors, this leads me to believe it's something to do with the DLL? 在windows 7数据库中,如果我将这两个查询复制并粘贴到pgadmin中,它们工作正常,没有错误,这让我相信它与DLL有关吗?

What doesn't make sense is this program working bug free on my Windows XP system while throwing this error constantly on Windows 7. 没有意义的是这个程序在我的Windows XP系统上运行bug,同时在Windows 7上不断抛出这个错误。

I also try a simple delete statement: 我也尝试了一个简单的删除声明:

DELETE FROM "db_events"; DELETE FROM "db_events_counts";

But that also ends in the same error. 但这也以同样的错误结束。

Is there anything I am missing? 有什么我想念的吗? Does Npgsql need to be compiled in the same windows environment as it's run in? Npgsql是否需要在运行时在相同的Windows环境中编译? or is there some subtle difference between windows 7 and windows XP with postgres that I am not getting. 或者Windows 7和Windows XP之间是否存在一些微妙的区别,而且我没有得到postgres。

Any help or information on the topic would be greatly appreciated. 任何有关该主题的帮助或信息将不胜感激。


Due to questions about the connection, here is what i have tried: 由于有关连接的问题,这是我尝试过的:

Server=localhost;Port=5433;User Id=databaseuser;Password=databaseuser_123;Database=db123;
Server=127.0.0.1;Port=5433;User Id=databaseuser;Password=databaseuser_123;Database=db123;
Server=10.223.132.123;Port=5433;User Id=databaseuser;Password=databaseuser_123;Database=db123;

The last being the local machines IP address. 最后一个是本地机器的IP地址。


Here is a short log of the program connecting and disconnecting from the server on Win 7: 以下是在Win 7上连接和断开服务器程序的简短日志:
// connecting //连接

2012-08-27 11:26:00 EST ERROR:  relation "db_events" does not exist at character 13
2012-08-27 11:26:00 EST STATEMENT:  DELETE FROM "db_events"; DELETE FROM "db_events_counts";
2012-08-27 12:52:29 EST ERROR:  relation "db_events" does not exist at character 13
2012-08-27 12:52:29 EST STATEMENT:  INSERT INTO "db_events" VALUES ('114','1','2','1', to_timestamp('2012/08/27 12:52:29', 'YYYY/MM/DD HH24:MI:SS'),'2012', '8', '27', '12', '52', '29', '35' );

// disconnecting //断开连接

2012-08-27 11:26:07 EST LOG:  could not receive data from client: No connection could be made because the target machine actively refused it.
2012-08-27 11:26:07 EST LOG:  unexpected EOF on client connection

The strange and erratic behaviour seen here, and discussion in the comments, suggests that the system catalogs (in the pg_catalog schema) may've been modified directly - perhaps an attempt to REVOKE some permissions. 奇怪和反常行为在这里看到,和讨论中的意见,建议,系统目录(在pg_catalog模式)may've直接修改-也许试图REVOKE一些权限。

That's not a good idea. 那不是个好主意。 The system catalogs should really only be modified by experts. 系统目录应该只由专家修改。 That's one of the reasons only superuser accounts can modify them directly, and one of the many reasons you should not use superuser accounts in day-to-day operation. 这只是超级用户帐户可以直接修改它们的原因之一,也是您不应在日常操作中使用超级用户帐户的众多原因之一。

Unless you know exactly what was done and can undo it, I'd recommend reverting to a working copy of the database like the one on your known-good XP machine. 除非你确切地知道做了什么并且可以撤消它,否则我建议你恢复数据库的工作副本,就像你已知良好的XP机器上那样。 GRANT ing access to public in pg_catalog sounds like it helped, but who knows what else has been done. GRANT荷兰国际集团获得publicpg_catalog听起来像它的帮助下,但谁知道还有什么已经完成。

If this were my DB I'd take a pg_dump of each database and a pg_dumpall --globals-only and restore it to a spare DB to make sure it looked complete. 如果这是我的数据库,我会使用每个数据库的pg_dump和一个pg_dumpall --globals-only并将其恢复到备用数据库以确保它看起来完整。 I'd then stop Pg and re-initdb. 我然后停止Pg并重新initdb。 That's a bit of a pain on Windows, though, so you might well be fine with just backing up the damaged database, DROP ping it, re-creating it and restoring the data back into it. 不过,这对Windows来说有点痛苦,所以你可能只需备份损坏的数据库, DROP ping它,重新创建它并将数据恢复到它中就可以了。

Figured it out with the help of CraigRinger. 在CraigRinger的帮助下计算出来。

Even though the user I was logging in as was the owner of the database, he did not have permission to look into anything under the public schema. 即使我登录的用户是数据库的所有者,他也没有权限查看公共模式下的任何内容。

This was discovered using: 这被发现使用:
select * from public.db_events

which, instead of throwing a relation not found error, threw an access is denied error. 其中,而不是抛出relation not found错误,抛出access is denied错误。

After changing the user I was logging in as to a superuser and ticking all the check boxes under "role privileges", the relation not found error didn't occur any more. 更改用户后,我登录superuser并勾选“角色权限”下的所有复选框, relation not found错误错误。

PostgreSQL folds all identifiers to lower-case. PostgreSQL将所有标识符折叠为小写。 This is PostgreSQL behavior, and has nothing to do with Npgsql - the latter simply passes along your SQL as you wrote it. 这是PostgreSQL的行为,与Npgsql无关 - 后者只是在编写时传递你的SQL。 You can switch to all-lowercase table names, in which case you no longer need the quotes. 您可以切换到全小写表名,在这种情况下,您不再需要引号。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM