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 919381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:32:06+00:00 2026-05-15T18:32:06+00:00

I have a script in PostgreSQL which restores test database from dump every night.

  • 0

I have a script in PostgreSQL which restores test database from dump every night. The database is accessed by app servers and processes with connection pool which keeps a few connections alive at all times.

So the script restores dump into my_temp_database. Then it should rename my_database to my_old_database, my_temp_database to my_database, and eventually drop my_old_database.

How can I disconnect all clients, superuser or not, from my_database, so that it can be renamed? How I can I temporarily prevent them from reconnecting?

Is there a better way to do what I need?

  • 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-05-15T18:32:06+00:00Added an answer on May 15, 2026 at 6:32 pm

    To mark database ‘applogs’ as not accepting new connections:

    update pg_database set datallowconn = false where datname = 'applogs';
    

    Another possibility would be to revoke ‘connect’ access on the database for the client role(s).

    Disconnect users from database = kill backend. So to disconnect all other users from “applogs” database, for example:

    select pg_terminate_backend(procpid)
    from pg_stat_activity
    where datname = 'applogs' and procpid <> pg_backend_pid();
    

    Once you’ve done both of those, you are the only user connected to ‘applogs’. Although there might actually be a delay before the backends actually finish disconnecting?

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

Sidebar

Related Questions

I have an existing database(Postgresql). How can i create models from it? How can
I have a PHP/PostgreSQL/Oracle-script which displays links as tags, which can be clicked to
I have a MySQL 5 database that is updated every 5 minutes from a
I have a database in PostgreSQL which is named DATA in all caps. When
In my rails app I have a seeds.rb script which inserts lots of records.
I have script which allows to display Bing search results. I can call for
i have a script which is for virtual keyboard, i am facing some problem
I'm migrating a site from mysql to PostgreSQL (which I really like so far)
I have a php script which returns some values with special characters, especially single
I'm using PG pool, which executes a failover script when a database node goes

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.