我正在运行PostgreSQL 9.6(在Docker中,使用postgres:9.6.13映像)和psycopg2 2.8.2。
我的PostgreSQL服务器(本地)托管两个数据库。我的目标是在一个数据库中创建物化视图,该数据库使用Postgres的外部数据包装器使用另一个数据库中的数据。我通过使用psycopg2的Python脚本来完成所有这些操作。
只要创建实例化视图不会花费太长时间(即,如果要导入的数据量不太大),这就会很好。但是,如果该过程花费的时间超过大约250秒,则psycopg2会引发异常
gulp buildNoRev && gulp connect | ng serve --proxy-config proxy.conf.json --port 4201 --base-href /transactionnel/v2/
在Postgres的日志中找不到错误消息(或与此相关的任何消息)。
如果从SQL客户端(Postico)中完成,则材料化视图的创建将成功完成。
此代码大致说明了我在Python脚本中正在做的事情:
System.setProperty("webdriver.chrome.driver", "/home/dev2/Downloads/newchromedriver/chromedriver");
WebDriver m = new ChromeDriver();
m.get("https://.130:2096/");
m.manage().window().maximize();
m.findElement(By.xpath(".//input[@id='user']")).sendKeys("talconnect.com.au");
m.findElement(By.xpath(".//input[@id='pass']")).sendKeys("$}+FdVI5$o!G");
m.findElement(By.xpath(".//button[@id='login_submit']")).click();
m.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// m.manage().timeouts().implicitlyWait(2,TimeUnit.MINUTES);
m.switchTo().frame("mailFrame");
Thread.sleep(9000);
List<WebElement> xpath11 = m.findElements(By.xpath(".//tr[contains(@id, 'rcmrow')]"));
int count = xpath11.size();
System.out.println(count);
for (WebElement link : xpath11) {
String sd = link.getText();
File source = new File("/home/dev2/Desktop/readexcell.xlsx");
FileOutputStream input = new FileOutputStream(source);
XSSFWorkbook wb=new XSSFWorkbook();
XSSFSheet sheet=wb.createSheet("data");
int i;
for(i=0; i<=count; i++) {
XSSFRow excelRow = sheet.createRow(i);
XSSFCell excelCell = excelRow.createCell(i);
excelCell.setCellType(CellType.STRING);
excelCell.setCellValue(sd);
}
input.flush();
wb.write(input);
答案 0 :(得分:2)
在keepalive
调用中添加psycopg2.connect
参数似乎已经解决了问题:
self.db = pg.connect(
dbname=config.db_name,
user=config.db_user,
password=config.db_password,
host=config.db_host,
port=config.db_port,
keepalives=1,
keepalives_idle=30,
keepalives_interval=10,
keepalives_count=5
)
我仍然不知道为什么这是必要的。我找不到其他描述过在Docker中使用Postgres时必须使用keepalives
参数关键字的人,以便能够运行耗时超过4-5分钟的查询,但是很明显,没有人知道注意到了吗?
答案 1 :(得分:0)
在https://stackoverflow.com/a/45627782/1587329中提到的新超时之后,PostgreSQL 9.6可能会终止您的连接。在这种情况下,您可以设置
statement_timeout
中的postgresql.conf
但它是not recommended。
它可能在Postico中起作用,因为该值已在其中设置。
要记录错误,您需要将log_min_error_statement
设置为ERROR
或更低,以使其显示。