Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:16:58+00:00 2026-06-03T06:16:58+00:00

I have some kind of (basic) logging with user actions in a postgreSQL database.

  • 0

I have some kind of (basic) logging with user actions in a postgreSQL database.
In order to gain performance, I execute all log inserts asynchronously to let the script continue and not wait until log entry is created.

I use prepared statements everywhere to prevent SQL injections and load them in an as-needed basis.

The problem comes when there are pending results to be fetched from a previous async query when I prepare a statement. (PostgreSQL says there are pending results to be fetched prior to prepare a new statement)

So as a workarround, I gather all pending results (if any) and ignore them to make PHP and PostgreSQL happy before preparing any statement.

But with that workarround (as I see it), I miss the performance I could gain by executing asyncronously as I have to gather the results anyway.

Is there any way to asynchronously execute a prepared statement and deliberatelly tell postgres to ignore results?

Inside my PostgreSQL class, I am calling prepared statements with

pg_send_execute($this->resource, $name, $params);

and prepairing them with

//Just in case there are pending results (workarround)
while (pg_get_result($this->resource)!==FALSE);
$stmt = pg_prepare($this->resource, $stmtname, $query);

Any help will be apreciated.

UPDATE: All asynchronous queries I am using are only INSERT ones, so it should be safe (theoretically) to ignore their results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:17:00+00:00Added an answer on June 3, 2026 at 6:17 am

    The only thing that is asynchronous is your communication with PostgreSQL server – your database has to process everything sequentially.

    My proposal:

    If you have to use PostgreSQL for logging, use a separate database connection for logging purposes and get a connection pool sitting between your script and database – auth in PostgreSQL is costly and takes some time, this will cut it down. Acquiring a second connection will take some time, but if you use this method it will be faster than one without connection pool.

    Depending on your reliability requirements you should use autocommit (to never lose a log entry when PHP crashes). You may want to use an UNLOGGED table (available since PostgreSQL 9.1) if you don’t care about reliability on databse end (faster inserts as your data skips WAL) or if you don’t use replication or don’t need to have logs replicated.

    As a speed optimization, your log table should have no indexes because they would have to be updated on each insert. If you need them, create a second table and move data in a batch (every X minutes or every hour).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nice DataGridView showing what is basically some kind of log data
I have some kind of problem with jQuery selectors. Let's say i want to
I want to have some kind of single list that is initialized in a
I have a question about reflection I am trying to have some kind of
Here's a problem. Developers have some kind of a task (develop certain feature), which
I've figured I have to do some kind of API where the Android app
I have a need for some kind of information that is in essence static.
Suppose you have a subsystem that does some kind of work. It could be
Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
I'm kind of new to WPF although I have some experience in Forms, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.