How Do You Run a SQL Query to Identify the Primary Key of a Table in a PostgreSQL Database?

Problem scenario
You are using PostgreSQL and currently administering a database you inherited from a different company.  You want to determine the primary key of a given table.  How do you identify the primary key of a table?

Solution
Modify the query below so you replace “contint” with the name of the table you are interested in.  The result of this SQL query will be the primary key of that table.

How Do You Create a Primary Key in a PostgreSQL Table That Already Exists?

Problem scenario
You have a table that you would like to have a primary key.  You would like to add a new column to be the primary key.  How do you do this?

Solution
Here is a SQL command that is an illustration.  Assuming the table’s name is “contint” and the new column you want to add is “continual_col” with a value type of integer,

How Do You Troubleshoot the Ansible Message ‘Error while linking: [Errno 2] No such file or directory … “state”: “absent”‘?

Problem scenario
You are using the file module in Ansible.  But you get the error ‘Error while linking: [Errno 2] No such file or directory … “state”: “absent”‘.

What should you do?

Solution
Some people get this problem with different versions of Ansible 2.x.  It is documented on this external page.

Rewrite your Ansible playbook so it uses a “shell” module and some “ln -s” command.

How Do You Solve This SQL Problem When You Receive the Message “ERROR: Syntax Error at or Near”?

Problem scenario
You are trying to update a SQL table with a SQL statement (using the “UPDATE” keyword).  You keep getting “ERROR:  syntax error at or near” with a reference of the value you are trying to give to a cell in a row in a SQL table.  You verified you have no extra commas, apostrophes, or semicolons in your SQL UPDATE statement.  You verified that the columns exist in the table and are spelled correctly in your UPDATE statement.

How Do You Troubleshoot a Car Alarm Remote Control Device (aka Key Fob)?

Problem scenario
Your remote control to the car alarm (aka key fob) is not working reliably.  You need to get into your car or at least disarm the the alarm on-demand.  How do you get the keyless entry device (or the alarm remote control or key fob) to work reliably to it will deactivate or activate the alarm when you need it to happen?

Solution
Possible solution #1
Tighten the screws in the back or the side. 

How Do You Log into a Windows Server in Google Cloud Platform?

Problem scenario
You created a Windows server in GCP.  How do you obtain credentials and connect to it?

Solution
1.  Make sure the firewalls allow for the connection.  See this posting if you need to change that.

2.  In the GCP console, go to Computer Engine -> VM Instances.  

3.  Go to the VM you want to connect to. 

How Do You View Failed User Login Attempts to a PostgreSQL Instance?

Problem scenario
You are running a LAPP application on Ubuntu Linux with PostgreSQL.  A user has complained that she cannot log into your Postgres database via a LAPP application.  You are not sure if the attempts are even registering of if the user is entering an incorrect username.  How do you look at a log to see a history of unsuccessful attempts at logging into the Postgresql database?

Solution
Examine this file: /var/log/postgresql/postgresql-x.y-main.log

(Substitute x.y with the major and minor versions of PostgreSQL you are running e.g.,

How Do You Detect the Hard Drive Letter That Your PowerShell Script (.ps1 File) Is Saved On?

Problem scenario
You have a PowerShell script that you want to be able to detect the hard drive letter it resides on.  How can PowerShell detect the hard drive letter that the .ps1 file itself is stored on?

Solution
Use this command: (get-location).drive.name

To get the drive letter to be in a variable named $dl, use this:
$dl = (get-location).drive.name

Now you can use $dl as the drive letter in the PowerShell script.  

How Do You Solve the Problem “Cannot find a usable libpq.dll. Please launch heidisql64.r5168.exe from the directory where you have installed it”?

Problem scenario
In Windows 7 you start (or launch) HeidiSQL.  You try to connect to a remote server but you get the error “Cannot find a usable libpq.dll. Please launch heidisql64.r5168.exe from the directory where you have installed it.”  How do you solve this problem?

Solution
Uninstall HeidiSQL and install the latest one from here.  If you download the latest build,

How Do You Create an Option to Logout for a PHP Web Page to Destroy the Session?

Problem scenario
You have a LAMP (or LAPP) web page application.  The PHP code uses the session() functionality.  Once a user logs in successfully, he/she can browse to successive web pages.  You want to at least allow the user the opportunity to destroy the session (and terminate the authentication session).  How do you do this?

Solution
#1  Modify the .php file that you want to have the logout feature.