0

We're in the process of optimizing a Django powered website and therefore we're anaylsing PostgreSQL logs - looking for long running queries that may be tuned in some way.

We stumbled upon a certain type of (sometimes extremely) long running queries, which we cannot find the source for. They look like this:

COPY public.my_table_name (id, field1, field2, field3, ...) TO stdout;

What could be the cause of these queries? They are rather rare, but they can run up to a minute! Is this something internal of PostgreSQL? Does Django itself trigger them?

3
  • 1
    This looks like somebody leaching your database. PG sends the contents of your table to stdout, but that output may be piped into some other program or some network channel. Have you been hacked? Commented Sep 11, 2015 at 22:27
  • A hack is extremely unlikely. On the one hand, security is very tight on this system, while on the other hand, there's virtually nothing to gain from hacking this database except for about a million email addresses. Although email addresses may be an interesting target, there are likely much easier ways to obtain such than hacking into this system. Also, we don't see any hint of an attack. And the entries appear since at least a year ago - here and there. Commented Sep 12, 2015 at 4:18
  • We're creating database dumps regularly and store them as zip files. Those are full dumps of the whole database. Is it possible that pg_dump causes these entries? Are tables dumped (concerning the log file) sequentially with pg_dump? Commented Sep 12, 2015 at 4:33

1 Answer 1

3

These are most likely issued by pg_dump, which as you say you are using to backup the database.

To confirm this is the case I recommend you alter your logging so that it shows details of the connection that commands are being issued from, including the application name. You can find details of how to configure this in the logging section of the manual.

For example you can set log_line_prefix to %a %r %p which would include the application name, remote IP/port and PID of backend (which I sometimes find useful).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for supporting my suspicions. I can test this in about a week; For now, I already accept the answer. If it's something else that's causing the log entries, I'll let you know then.
Perfect, that was it. We just tested and confirmed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.