Skip to main content


Force Deleting a Postgres Database

pgAdmin doesn't allow deleting a database when there are existing connections present to the database and results in below error.

To overcome the above error, we need to force disconnect all connected users via a query and then try deleting the database.

/* Terminate all Database conenctions except current one */
Recent posts

Android Activity Quick How Tos

Here is a collection of how-to articles related to Android UI.
Skipping an Activity/Screen on Back Button Press For example, say you have 3 activities, which are navigated as below.
Activity 1 -> Activity 2 -> Activity 3

Now from Activity 3, user can press back button to go to Activity 2 from where he can again press back button to go to Activity 1. Normally this is what you would expect.

But what if the Activity 2 is a intermediate splash screen which is shown temporarily and you want the user to go to Activity 1 from Activity 3 on back button press? It's pretty simple - you end Activity 2 when you go to Activity 3. Now, when user presses back button, it will go to Activity 1.

For ending the Activity 2, you need to call the finish(); method after starting Activity 3.

intent = Intent(this, intent.putExtra("Param Value", param1) startActivity(intent) finish(); Using an Existing Activity instead of Creating a New Activity Consider …

Stopping and Starting Postgres SQL Database Server

Go to the Postgres installation bin directory, which would be something likeC:\Program Files\PostgreSQL\9.5\binIn the windows explorer path, type "cmd" and press Enter to launch Command Prompt window.Command to Stop the Postgres Database Serverpg_ctl -D "..\data" stopCommand to Start the Postgres Database Serverpg_ctl -D "..\data" start Command to Restart the Postgres Database Serverpg_ctl -D "..\data" restart You might need to keep the above command line window open for the database to continue working. If anyone has found an alternative to avoid keeping the window open, please let me know in the comments.

Note: If you are facing any issues, you need to run the Command Prompt as administrator and use the below command to switch to the Postgres bin directory and then use the above command.
 cd C:\Program Files\PostgreSQL\9.5\bin

Creating Migration Query in Postgres

During development of an application, its a good practice to have multiple database instances - one for production and one for development/testing. The development/testing database would be the one you will be using for testing.

But what would you do if there is a change required in the database schema itself - like adding a column or changing the data type of a column or deleting a column? Duplicating the changes in multiple instances of the database is error prone and not efficient usage of time. That's where migration query comes in!
Steps to Create Migration Query 1. Open pgAdmin and connect to your database.
2. Right click on the specific table you would like to change and click on Properties.

3. Make necessary changes to the table - Eg: Like adding a new column.

4. Go to SQL tab. This would have generated an equivalent query for the change(s) you have made. Copy the query paste in a Notepad.

5. Do step 4 for all the changes you would like to make in the database. For each c…

Quick Links for Android Kotlin

This post has a collection of useful links related to development of Android applications using Kotlin. Getting Started with KotlinGetting Started with Android and KotlinKotlin Reference ManualPDF Version  Useful How TosAdding Internet Permission for your Android Application Leveraging Power of Functions in Kotlin API Request in Android using Kotlin  Useful Extensions (Kotlin + Java)AnkoAnko Commons: a lightweight library full of helpers for intents, dialogs, logging and so on;Anko Layouts: a fast and type-safe way to write dynamic Android layouts;Anko SQLite: a query DSL and parser collection for Android SQLite;Anko Coroutines: utilities based on the kotlinx.coroutines library.Parsing JSON Using org.json (built-in) - ExampleGSON - ExampleJacksonJSON Path (Similar to XPath for XML)  Web ScrapingJSoup - ExamplePicasso -  A powerful image downloading and caching library for Android Reusable Packages Open Source Kotlin Reusable Packages Free Online Courses for Learning KotlinDeveloping…