Blog Posts

Visualizing PostgreSQL Database Schemas with SchemaSpy

Dec. 9, 2024

When working on a database-heavy project, it can be challenging to keep track of all the relationships between tables, columns, and constraints. This is where SchemaSpy shines. SchemaSpy is an open-source tool that analyzes database schemas and generates detailed, interactive diagrams and reports. These visualizations can help developers, database administrators, and stakeholders better understand and maintain the database structure.

# Step 1: Check if Java is installed
 # Ensure Java is installed by running the following command:
 # java -version
 # If Java is not installed, install it using the appropriate method for your system.
 # Example for Ubuntu:
 # sudo apt install default-jre

 # Step 2: Download SchemaSpy
 # Download the latest SchemaSpy jar file from:
 # https://github.com/schemaspy/schemaspy/releases
 # Save the file in a directory you can reference later, e.g., /path/to/schemaspy.jar.

 # Step 3: Download PostgreSQL JDBC driver
 # Download the PostgreSQL JDBC driver from:
 # https://jdbc.postgresql.org/
 # Save the driver as a .jar file in a directory you can reference later, e.g., /path/to/postgresql.jar.

 # Step 4: Prepare your PostgreSQL database
 # Ensure you have a running PostgreSQL instance.
 # If you have a SQL dump, you can restore it using:
 # psql -U your_user -d your_db < dump_file.sql
 # Ensure the database server is running and the user has proper access rights.

 # Step 5: Run SchemaSpy
 # Use the following command to analyze your database and generate the SchemaSpy report:
 # java -jar /path/to/schemaspy.jar \
 #   -t pgsql \                      # Specify PostgreSQL as the database type
 #   -host localhost \               # Replace with your database hostname
 #   -port 5432 \                    # Default port for PostgreSQL
 #   -db your_db \                   # Replace with your database name
 #   -u your_user \                  # Replace with your database username
 #   -p your_password \              # Replace with your database password
 #   -dp /path/to/postgresql.jar \   # Path to the PostgreSQL JDBC driver
 #   -o /path/to/output_directory    # Directory where the report will be saved

 # Example:
 java -jar schemaspy.jar -t pgsql -host localhost -port 5432 -db testdb -u postgres -p mypassword -dp postgresql-42.6.0.jar -o ./output

 # Step 6: View the report
 # After running SchemaSpy, open the generated report by accessing the `index.html` file in the output directory.
 # Example:
 # Open in your default browser:
 # xdg-open /path/to/output_directory/index.html     # For Linux
 # open /path/to/output_directory/index.html         # For macOS
 # Or manually navigate to the output directory and open the file in your browser.


Hello World!

Dec. 8, 2024

Hello there, tech enthusiasts! I’m thrilled to welcome you to MiHanDo’s Blog—a space where I document my personal learning journey and share my experiences in the ever-evolving world of technology.


MiHanDo?

If you’re curious about the name MiHanDo, here’s the story:

  • “Han” means “middle” in Japanese.
  • “Do” translates to “way”.

Together, it represents “my way” or “the path in the middle.” For me, it’s about finding balance, staying curious, and carving out a path that aligns with my own growth and exploration.


My blog, my perspective

This blog is a personal notebook—a place where I:

  • share my opinions on tech trends and tools,
  • document what I’ve learned, and
  • create resources and cheatsheets for my own use.

Everything you’ll find here comes from my own journey as a developer. I’m not claiming to have all the answers, but I’m eager to share what I’ve discovered along the way.


Who can join?

While this blog is primarily for my own benefit, anyone is welcome to join in!

Whether you’re:

  • on a similar learning path,
  • curious about new coding skills, or
  • looking for practical tips and ideas,

You’re invited to explore, learn, and grow alongside me.


What you’ll find here

Here’s a glimpse of what I’ll be sharing:

  • programming languages I’m diving into,
  • frameworks I’m exploring,
  • best practices I’m adopting, and
  • my go-to cheatsheets for quick references.

Think of this blog as a collection of my own thoughts and discoveries, open for anyone who finds them helpful or inspiring.


A journey of growth

For me, technology is as much about learning as it is about building. This blog is my way of documenting that growth, and I hope it inspires you to stay curious and keep exploring.

So, grab your favorite beverage, dive into a post, and feel free to engage with my journey. Let’s navigate this exciting world of tech together!

Cheers,
MiHanDo