Live data from Hacker News

Joe, a Postgres query optimization bot

postgres.ai

31–40 of 40 posts

Re: Joe, a Postgres query optimization bot

#32
Semi related, SQL Server have query store feature which records query insights on production db and in SSMS you can see the query statistics on various metrics like resource uses, execution counts etc along with query plan applied.

I haven't dug deep into SQL server yet, but query store suggestions are good enough for now.

Re: Joe, a Postgres query optimization bot

#34
post #32

Semi related, SQL Server have query store feature which records query insights on production db and in SSMS you can see the query statistics on various metrics like resource uses, execution counts etc along with query plan applied. I haven't dug deep into SQL server yet, but query store suggestions are good enough for now.

We call it macro-analysis -- the analysis of SQL workload as a whole, with call counts, timing, memory-related metrics, etc.

Currently, Joe helps with micro analysis: you take just one SQL query, don't think about others and solve the task of optimizing this particular query.

For "macro", Postgres ecosystem has pg_stat_statements (and our tool postgres-checkup https://gitlab.com/postgres-ai/postgres-checkup for automated health checks builds reports on top of it), pgBadger to analyze logs, auto_explain to capture execution plans.

Building the "bridge" between macro- and macro-analyses is a very interesting topic. I'm going to give a talk about this particular topic at the next PGCon.

Re: Joe, a Postgres query optimization bot

#35
post #31

How hard would it be to implement the Discord Bot protocol? I'd be willing to help on this front, and it'd be a nice way for me to get my hands wet on Go too. Thanks in Advance.

Cool!

Please join our Community Slack https://database-lab-team-slack-invite.herokuapp.com/ and ping me there -- let's discuss it.

We're refactoring the main code of Joe right now, to improve its extensibility. The main purpose is to simplify the process of adding new protocols.

Re: Joe, a Postgres query optimization bot

#36

I've used Joe quite a bit, and all I can say is that it's a great idea that solves a noticeable problem: troubleshoot your queries. It may not look like is a hard challenge: but the reality is that most troubleshoot them in production, which means that: a) you need access to production, when you shouldn't; b) you run queries in production, potentially affecting -sometimes noticeably- production workloads. Joe provisi…

> but the reality is that most troubleshoot them in production I find this hard to believe. Maybe on the very rare occasion where the problem is tied to production and irreproducible elsewhere, but my experience has been that most troubleshooting happens on development, testing, staging, etc servers. > and gives you a full copy of the database for you, with real data Other than for small toy databases, I don't see ho…

> I find this hard to believe. Maybe on the very rare occasion where the problem is tied to production and irreproducible elsewhere, but my experience has been that most troubleshooting happens on development, testing, staging, etc servers.

Let me rephrase: many may troubleshoot in dev/staging, but that's not the right thing to do. Query execution plans can change completely based on data volume and even with the data itself. Databases use detailed statistics about the data to influence the planner's decision.

Hence, tuning a query on an environment without production data can lead to query optimizations that are either irrelevant or totally wrong in production. I have seen this countless times in my professional experience.

> Other than for small toy databases, I don't see how this would work for large databases.

Since it uses cloning at the volume/fs layer, the size of the database is irrelevant --only the rate of changes matter.

> You can test, optimize, etc queries on non-production servers.

No, you cannot, as I mentioned above. It's a waste of effort and can only lead to the false illusion that your query is good --and then beat you in production.

Re: Joe, a Postgres query optimization bot

#37
post #6
post #3

So... this thing gives full read/write/ddl access to production data ...via Slack? That is a security nightmare. Hard pass.

Yeah, seriously. I wonder how they thought slack and chat interface would be a better than a CLI app...

Joe running in Slack is indeed a way to simplify and speed-up SQL optimization workflow for developers, as it takes seconds to get initial query execution plans and optimization recommendations.

>... With a Slack interface, so you don't need to bother with connection, provisioning, credentials and decommissioning.

It's worth noticing that Joe is a use case of Database Lab (https://gitlab.com/postgres-ai/database-lab) and it's still possible to use Database Lab features like thin-clones provisioning of production-sized databases and fast data state reset with Database Lab client CLI (https://postgres.ai/docs/database-lab/6_cli_reference) for purposes of SQL optimization without Slack integration. If a user has sufficient access to the data they can provision thin-clone with Database Lab client CLI and use psql to work with the clone.

Also, we have plans to add support of recommendations and statistics in CLI and REST API to the support of various messaging platforms in the future.

Re: Joe, a Postgres query optimization bot

#38

Earlier quoted context omitted.

> but the reality is that most troubleshoot them in production I find this hard to believe. Maybe on the very rare occasion where the problem is tied to production and irreproducible elsewhere, but my experience has been that most troubleshooting happens on development, testing, staging, etc servers. > and gives you a full copy of the database for you, with real data Other than for small toy databases, I don't see ho…

> I find this hard to believe. Maybe on the very rare occasion where the problem is tied to production and irreproducible elsewhere, but my experience has been that most troubleshooting happens on development, testing, staging, etc servers. Let me rephrase: many may troubleshoot in dev/staging, but that's not the right thing to do. Query execution plans can change completely based on data volume and even with the dat…

> Let me rephrase: many may troubleshoot in dev/staging, but that's not the right thing to do.

Maybe we have a different definition of "troubleshoot". Also, dev and/or staging should have similar data/specs/etc to production.

> Query execution plans can change completely based on data volume and even with the data itself.

Yes. That's why you could have your production server generate/log actual query plans for queries that are causing you problems. You could even set performance (cpu,io,bandwidth,etc) thresholds for your server to log. Of course that's in addition to the profile/monitoring data you have on the server.

> Hence, tuning a query on an environment without production data can lead to query optimizations that are either irrelevant or totally wrong in production. I have seen this countless times in my professional experience.

Well then your issue is that your dev/staging setup is poor. How or what do you even develop, test and troubleshoot? Might as well develop, test and troubleshoot straight on production.

> Since it uses cloning at the volume/fs layer, the size of the database is irrelevant --only the rate of changes matter.

Size still does matters. And as I mentioned, it still has a problem with security.

> No, you cannot, as I mentioned above. It's a waste of effort and can only lead to the false illusion that your query is good --and then beat you in production.

"waste of effort"? Developing, testing, troubleshooting, etc should be done off production. It's only on the rare cases that you should troubleshoot on production. This is best practices and basic security.

Unless you are working on internal office setup which isn't facing the outside world and where security and uptime doesn't matter. Your comment reminds me of people saying using "admin/root" account for everything is fine because everything else is "waste of effort". Do you even have a dev/staging setup? What do you use that for?

Everyone's professional experience is different, but I've never heard anyone claim "many may troubleshoot in dev/staging, but that's not the right thing to do". Not the right thing to do?

In my professional experience, the testing/troubleshooting is done on dev/staging. Once we feel everything is up to snuff, code gets pushed to production. If there are issues on production, we try to replicate it on dev/staging/etc and troubleshoot it. Most of the time, we find the bug/issue. On the rarest of occasions do we have to troubleshoot directly on production which serve our company and especially our clients who have SLAs with us. Your cavalier attitude about production is something I've yet to come across. But if it works for you, then I guess that's all that matters.

Re: Joe, a Postgres query optimization bot

#39

Earlier quoted context omitted.

> I find this hard to believe. Maybe on the very rare occasion where the problem is tied to production and irreproducible elsewhere, but my experience has been that most troubleshooting happens on development, testing, staging, etc servers. Let me rephrase: many may troubleshoot in dev/staging, but that's not the right thing to do. Query execution plans can change completely based on data volume and even with the dat…

> Let me rephrase: many may troubleshoot in dev/staging, but that's not the right thing to do. Maybe we have a different definition of "troubleshoot". Also, dev and/or staging should have similar data/specs/etc to production. > Query execution plans can change completely based on data volume and even with the data itself. Yes. That's why you could have your production server generate/log actual query plans for querie…

Ideally, you would be absolutely right and I would not disagree with you. But I strongly do, based on many years of experience in the field.

Out of all the customers we help with their Postgres infrastructure, and that includes several $B companies, I have found none to have either: * Dev environments dimensioned similarly to production. Actually, this typically neither happens on staging and sometimes not even in QA. * All except QA, if any, have the same data as production.

So in practical terms, I haven't seen it is possible to troubleshoot on dev/test/staging/QA environments, least to have a copy of the full database. This is reasonable, too: how all developers may have 5TB of data on their laptops? (leaving aside all privacy and data protection considerations).

That's why having a tool, Joe, to light provision production-like environments, that are disposable, where you can troubleshoot your queries, is for me a very nice approach to this problem, and the one I recommend.

Post reply on HN