PostgreSQL performance test script

In case you want to run a quick performance test (in simple terms of access to DB) on a PostgreSQL server, this can be done quickly through a python module called psycopg2. This is the python script I’ve used: #!/usr/bin/python3 import psycopg2 from psycopg2 import Error import time def create_connection(): """ create a database connection to a PostgreSQL database """ try: conn = psycopg2.connect( database="postgres", user="postgres", password="postgres", host="1.2.3.4", port="5432" ) print('Successfully Connected to PostgreSQL') return conn except Error as e: print(e) def check_table_exists(conn): """ check if a table exists in the PostgreSQL database """ cur = conn.cursor() cur.execute(f"SELECT 1;") def main(): # table_name = 'pg_auth_members' # create a database connection conn = create_connection() # check if table exists with conn: start_time = time.time() checks = 0 while True: check_table_exists(conn) checks += 1 elapsed_time = time.time() - start_time if elapsed_time > 0: tps = checks / elapsed_time print(f'Current TPS: {tps}') print (f'Current checks: {checks}') if __name__ == '__main__': main() In here you should update the database, user, password, host and port to something relevant to your environment. Everything else can stay the same. ...

April 24, 2024 · 2 min · 366 words · costin

How to fix "Could not connect to one or more vCenter Server"

Recently I had to fix a vCenter Server that was stopped working. The webpage displayed the following error, and the automated backup jobs stopped working. Could not connect to one or more vCenter Server systems: https://$VCENTER_FQDN:443/sdk The version is rather old and end of life (6.7), so VMware support was out of the question. Which means I had to do it all by myself. Great… After checking the logs for obvious errors, I’ve noticed that most services were stopped. And when I started them manually, the command hanged for a while and it returned this error after timeout expired: ...

September 28, 2023 · 6 min · 1088 words · costin

How to move artefacts in a Jfrog repository

This one will be a quick one. Recently I had to move several hundred artefacts from a Jfrog repo folder up one level. Easy peasy, right? But the problem was that manual work from GUI would take forever and my work time is limited so I had to find a different way. For this I’ve used an API call because I didn’t have access to jfrog cli tool. But the API call works for one file, not for a bulk move. And I had many to move. ...

September 28, 2023 · 2 min · 237 words · costin

How to automate your blog posts

Since I’ve transformed this website in a Blogging as a Service (BaaS) thing with the help of Github Actions and Github Pages my life was much easier. Let me help you do the same. First thing you’ll need is a domain. For this domain you will need a NS, and for this you can use CloudFlare for free. They offer a great service, btw.  ~/ dig in NS costinstefan.ro +short nola.ns.cloudflare.com. theo.ns.cloudflare.com. In CF you should define your zone, and this zone should include at least an A record that will point to Github Pages (my case). ...

February 17, 2023 · 3 min · 576 words · costin

How to restore a Kubernetes cluster after IP change

Recently I had to fix a kubernetes cluster which had its IP addresses changed. The team that changed the IP address on the machines also replaced the hostname in /etc/hosts. However, this is not enough. In order to restore the cluster, you also have to change the IP address in kubernetes cluster manifest files. [root@k8s-master ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 11.11.112.42 k8s-master 11.11.112.43 worker-k8s2 11.11.112.44 worker-k8s3 11.11.112.42 worker-k8s-control First I confirmed the manifest files include the old IP address of the master node (10.10.138.42): ...

January 18, 2023 · 2 min · 256 words · costin