Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
PostgreSQL 16 Administration Cookbook

You're reading from  PostgreSQL 16 Administration Cookbook

Product type Book
Published in Dec 2023
Publisher Packt
ISBN-13 9781835460580
Pages 636 pages
Edition 1st Edition
Languages
Authors (5):
Gianni Ciolli Gianni Ciolli
Profile icon Gianni Ciolli
Boriss Mejías Boriss Mejías
Profile icon Boriss Mejías
Jimmy Angelakos Jimmy Angelakos
Profile icon Jimmy Angelakos
Vibhor Kumar Vibhor Kumar
Profile icon Vibhor Kumar
Simon Riggs Simon Riggs
Profile icon Simon Riggs
View More author details

Table of Contents (15) Chapters

Preface First Steps Exploring the Database Server Configuration Server Control Tables and Data Security Database Administration Monitoring and Diagnosis Regular Maintenance Performance and Concurrency Backup and Recovery Replication and Upgrades Other Books You May Enjoy
Index

Checking whether a user is connected

Here, we will show you how to find out whether a certain database user is currently connected to the database.

Getting ready

If you are logged in as a superuser, you will have full access to monitoring information.

How to do it…

Issue the following query to see whether the user bob is connected:

SELECT datname FROM pg_stat_activity WHERE usename = 'bob';

If this query returns any rows, then that means that bob is connected to the database. The returned value is the name of the database that the user is connected to.

How it works…

PostgreSQL’s pg_stat_activity system view keeps track of all running PostgreSQL backends. This includes information such as the query that is being currently executed, the last query that was executed by each backend, who is connected, when the connection, transaction, and/or query were started, and so on.

There’s more…

Please spend a...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}