{"id":1957,"date":"2015-01-06T20:53:03","date_gmt":"2015-01-06T18:53:03","guid":{"rendered":"http:\/\/www.profelis.com.tr\/tr\/blog\/?p=1957"},"modified":"2023-02-01T10:58:13","modified_gmt":"2023-02-01T07:58:13","slug":"postgresql-101-bagli-kullanicilar","status":"publish","type":"post","link":"https:\/\/profelis.com.tr\/en\/2015\/01\/06\/postgresql-101-bagli-kullanicilar\/","title":{"rendered":"PostgreSQL 101: Connected Users"},"content":{"rendered":"<h2>PostgreSQL 101: Connected Users<\/h2>\n<p>one of the PostgreSQL system views\u00a0<strong>pg_stat_activity<\/strong>\u00a0It maintains a list of all currently running PostgreSQL background processes. This information includes which queries are running, the connected users and when they connected, as well as the start time of the active transaction and queries.<\/p>\n<p>To check if a specific user is connected to a PostgreSQL database:<\/p>\n<div class=\"page\" title=\"Page 206\">\n<div class=\"layoutArea\">\n<div class=\"column\">\n<pre>SELECT dbname FROM pg_stat_activity WHERE usename = 'tolga';<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>If this query returns a result, it means the user tolga is connected to the system. The value returned for the dbname column shows the database or databases to which the user tolga is connected.<\/p>\n<h2>\u201cIf we are looking for the answer to the question \u201dWhich computer are they connected from?\"<\/h2>\n<p>Generally, multiple processes might be connecting to the same database with the same username. In this case, you might want to know through which remote system the connections are being made. <strong>pg_stat_activity<\/strong> Its view also shows information about this. Namely, the IP address and connection ports of the connected system are located in this view. You can see who is connecting from where to databases connected with the same username as the IP address. On the other hand, port numbers show different sessions of the user with the same name connecting from the same remote client. In this case, the following query:<\/p>\n<pre>SELECT dbname, username, client_addr, client_port FROM pg_stat_activity ;<\/pre>\n<p>client_addr and client_port can show the respective client and its port, even including the process ID on the remote machine.<\/p>","protected":false},"excerpt":{"rendered":"<p>One of the PostgreSQL system views, pg_stat_activity, keeps a list of all currently running PostgreSQL background processes. This information includes which queries are running, connected users and when they connected, and the start time of running transactions and queries.<\/p>","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75,45],"tags":[48,60],"class_list":["post-1957","post","type-post","status-publish","format-standard","hentry","category-postgresql","category-yazi","tag-enterprisedb","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/posts\/1957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/comments?post=1957"}],"version-history":[{"count":0,"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/posts\/1957\/revisions"}],"wp:attachment":[{"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/media?parent=1957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/categories?post=1957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/profelis.com.tr\/en\/wp-json\/wp\/v2\/tags?post=1957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}