How can I configure the client timeout to yugabyte db server when running queries from psql? - psql

It seems like some queries are taking too long and I want to make the client wait longer for the query results?

By default there's no statement timeout:
yugabyte=# show statement_timeout;
statement_timeout
-------------------
0
(1 row)
yugabyte=# select pg_sleep(2);
pg_sleep
----------
(1 row)
yugabyte=# set statement_timeout to 1000;
SET
yugabyte=# select pg_sleep(2);
ERROR: canceling statement due to statement timeout
Can you tell me what error are you getting ?

Related

Failed to invoke procedure `apoc.cypher.mapParallel2`: Caused by: java.lang.RuntimeException: Error polling, timeout of 10 seconds reached

I am trying to count the number of relationships (c:Cell)-[:EXPRSSED_IN]->(g:Gene) by using the query:
CYPHER runtime=pipelined
MATCH (c:Cell)-[r:EXPRESSED_IN]->(g:Gene)
WHERE c.id >= 0 AND c.id < 6000
RETURN count(*) AS count;
The query executed successfully. However, it was slower than what I expected. It took around 6 seconds to count a list of around 45 million rows. I'm not sure if it's the "common case". Despite that, I want to speed it up furthermore by using parallel processing. Below is the query that I'm trying to execute:
MATCH (c:Cell)
WHERE c.id >= 0 AND c.id < 6000
WITH COLLECT(c) AS cells
CALL apoc.cypher.mapParallel2("MATCH (_)-[:EXPRESSED_IN]->(g:Gene) RETURN _.id AS cell_id, g.id AS gene_id",
{parallel:True, batchSize:1000, concurrency:20},
cells,
20) yield value
return COUNT(*) as count;
It gives me the error Failed to invoke procedure "apoc.cypher.mapParallel2": Caused by: java.lang.RuntimeException: Error polling, timeout of 10 seconds reached. My guess is that it has something to do with the sockets and ports as the server will probably open some sockets to communicate with its workers.
Could anyone provide me a solution? Thanks in advance.
UPDATE 1: I use neo4j enterprise version 4.1.3
UPDATE 2: My query is actually incorrect. I have fixed it and it executed successfully. However, now it's taking even more time than without doing any parallel processing
If you are interested in only the number of relationships of your nodes you can use relationship store with the following query:
MATCH (c:Cell)
WHERE c.id >= 0 AND c.id < 6000
RETURN sum(size( (c)-[:EXPRESSED_IN]->()) as count

How can you tell if a Influx Database contains data?

I'm currently trying to count the number of rows in an InfluxDB, but the following fails.
SELECT count(*) FROM "TempData_Quarantine_1519835017000_1519835137000"..:MEASUREMENT";
with the message
InfluxData API responded with status code=BadRequest, response={"error":"error parsing query: found :, expected ; at line 1, char 73"}
To my understanding this query should be checking all measurements and counting them?
(I inherited this code from someone else, so apologies for not understanding it better)
If you need a binary answer to the question "tell if a Influx Database contains data?" then just do
select count(*) from /.*/
In case if the current retention policy in the current database is empty (contains 0 rows) it will return just nothing. Otherwise it will return something like this:
name: api_calls
time count_value
---- -----------
0 5
name: cpu
time count_value
---- -----------
0 1
Also you can specify retention policy explicitly:
SELECT count(*) FROM "TempData_Quarantine_1519835017000_1519835137000"./.*/

Is it possible to add a parameter or something else to set timeout time of a query when we are running query through pgAdmin/psql client?

I want to run a query on a remote database with a timeout option.
For example :
Select * from XYZ table
if this query does not return any result within 2 min then automatically stop this query process.
dummy psql
#timeout select * from XYZ
is it possible to pass timeout parameter at run time without touching any conf file?
In psql use statement_timeout(n) where n is in milliseconds. Or you can set statement_timeout in postgresql.conf but it will affect all sessions.

How to turn off the time logging in Rails migrations with POstgres?

Everytime I run the migrations, I get a printout like this
Time: 0.393 ms
Time: 0.222 ms
Time: 0.174 ms
Time: 0.136 ms
Time: 0.138 ms
Time: 0.205 ms
Time: 0.468 ms
I'd like to disable this, but I can't seem to succeed. I already tried changing the postgresql.conf to disable client logging, etc. Nothing works.
set log_min_duration_statement =-1;
this can be set per session, per user, or per database, the above sets it for your session only.
alter user fred set log_min_duration_statement =-1;
alter database wordpress set log_min_duration_statement =-1;
setiting it to -1 disables it, setting it to 0 causes all queries to be logged.

Linq to Sql and T-SQL Performance Discrepancy

I have an MVC web site the presents a paged list of data records from a SQL Server database. The UI allows the user to filter the returned data on a number of different criteria, e.g. email address. Here is a snippet of code:
Stopwatch stopwatch = new Stopwatch();
var temp = SubscriberDB
.GetSubscribers(model.Filter, model.PagingInfo);
// Inspect SQL expression here
stopwatch.Start();
model.Subscribers = temp.ToList();
stopwatch.Stop(); // 9 seconds plus compared to < 1 second in Query Analyzer
When this code is run, the StopWatch shows an execution time of around 9 seconds. If I capture the generated SQL expression (just before it is evaluated with the .ToList() method) and cut'n'paste that as a query into SQL Server Management Studio, the execution times drops to less than 1 second. For reference here is the generated SQL expression:
SELECT [t2].[SubscriberId], [t2].[Email], [t3].[Reference] AS [DataSet], [t4].[Reference] AS [DataSource], [t2].[Created]
FROM (
SELECT [t1].[SubscriberId], [t1].[SubscriberDataSetId], [t1].[SubscriberDataSourceId], [t1].[Email], [t1].[Created], [t1].[ROW_NUMBER]
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY [t0].[Email], [t0].[SubscriberDataSetId]) AS [ROW_NUMBER], [t0].[SubscriberId], [t0].[SubscriberDataSetId], [t0].[SubscriberDataSourceId], [t0].[Email], [t0].[Created]
FROM [dbo].[inbox_Subscriber] AS [t0]
WHERE [t0].[Email] LIKE '%_EMAIL_ADDRESS_%'
) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN 0 + 1 AND 0 + 20
) AS [t2]
INNER JOIN [dbo].[inbox_SubscriberDataSet] AS [t3] ON [t3].[SubscriberDataSetId] = [t2].[SubscriberDataSetId]
INNER JOIN [dbo].[inbox_SubscriberDataSource] AS [t4] ON [t4].[SubscriberDataSourceId] = [t2].[SubscriberDataSourceId]
ORDER BY [t2].[ROW_NUMBER]
If I remove the email filter clause, then the controller's StopWatch returns a similar response time to the SQL Management Studio query, less than 1 second - so I am assuming that the basic interface to SQL plumbing is working correctly and that the problem lies with the evaluation of the Linq expression. I should also mention that this is quite a large database with upwards of 1M rows in the subscriber table.
Can anyone throw any light on why there should be such a high (x10) performance differential and what, if anything can be done to address this?
Well not sure about that. 1M rows with a full like can take quiet time. Is Email indexed? Can you run the query with Email% instead of %Email% and see what happen?

Resources