Dealing with the PostgreSQL connection refused error in the Phoenix framework

April 24th, 2024

Filed under: Web Development | Be the first to comment!

I wanted to learn to use the Phoenix web development framework. I was going through the Up and Running guide on the Phoenix framework’s site. When I ran the mix ecto.create command to create the database, I kept getting the following error:

15:45:35.314 [error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused – :econnrefused
** (Mix) The database for Hello.Repo couldn’t be created: killed

I noticed the following instruction in the tutorial:

Then configure your database in config/dev.exs

Without providing any more details. After some trial and error, I got the tutorial project up and running. I learned two requirements to get the mix ecto.create command to work.

  • You must start the PostgreSQL server.
  • Make sure the database user and password are correct.

Starting the Database Server

As someone inexperienced with web development, I didn’t realize you have to start a database server to create a database. I used the Postgres.app Mac app to create and start the database server.

Configuring the Database User and Password

The Phoenix tutorial assumes the database user and password are both postgres. If your postgres user has a different password, you must either change the password when running PostgreSQL or create a new user and password and use them in Phoenix.

Inside the project folder is a config folder. Inside that folder is a file called dev.exs. Open this file in a text editor. At the top of the file, you should see text similar to the following:

# Configure your database
config :hello, Hello.Repo,
  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  database: "hello_dev",
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

If your postgres user has a different password, enter it in the password field. If you create a new user, enter the name in the username field and the password in the password field.


Xcode 13 Missing Info.plist

February 7th, 2022

Filed under: Xcode | Be the first to comment!

If you create a new project in Xcode 13, you will notice there is no Info.plist file on the left side of the project window. How do you access Info.plist and add items to it?

  1. Select the project file from the left side of the project window to open the project editor.
  2. Select the app target from the list of targets on the left side of the project editor.
  3. Click the Info button at the top of the project editor.

Xcode13InfoPlist

The Custom Target Properties section contains the Info.plist file. Add, edit, and remove entries from there. Move the mouse arrow over an entry to show buttons for adding and removing entries.


Xcode 13.0 Does Not Have macOS 12 SDK

October 7th, 2021

Filed under: Xcode | Be the first to comment!

The Xcode 13 betas included the macOS 12 SDK. When Apple released iOS 15, they released Xcode 13.0. Because macOS 12 was still in beta during iOS 15’s release, Xcode 13.0 includes the macOS 11.3 SDK.

If you are writing a Mac app that uses something added in the macOS 12 SDK, such as SwiftUI’s element binding syntax, the code won’t compile, even if the new feature supports macOS 11.

To use the macOS 12 SDK, install one of the Xcode 13 betas until Apple releases macOS 12. When Apple ships macOS 12, they will ship a new Xcode version that includes the macOS 12 SDK.

UPDATE

Apple released Xcode 13.1 on October 25, 2021. Xcode 13.1 includes the macOS 12 SDK.


Xcode 13: Missing Products Folder

September 28th, 2021

Filed under: Xcode | Be the first to comment!

When you create a new project in Xcode 13, you will notice there is no Products folder in the project navigator. Choose Product > Show Build Folder in Finder to access the Products folder.


Xcode 12: Consolidated iOS App Project Templates

November 15th, 2020

Filed under: Xcode | Be the first to comment!

In Xcode 12 Apple consolidated many of their iOS app project templates into one template: App. If you are following a tutorial written for an older Xcode version that has templates like single view app and master-detail app, choose the App template.


How to Show Source Code on Reddit

October 3rd, 2020

Filed under: None | Be the first to comment!

I see many people who ask a programming question on Reddit and do one of two things to show their code:

  • They show a screenshot of their screen.
  • They use the inline code setting instead of creating a code block.

By doing these things, the people asking the question make their code extremely difficult to read, making it less likely they will get an answer.

RedditLongInlineListing

Notice how the code isn’t indented properly in the inline code block above. This sample isn’t too bad, but I have seen long inline code blocks that are almost unreadable.

The way to make a code listing readable on Reddit is to create a Markdown code block. Start by clicking the Markdown mode button on the right side of the toolbar above the text view for writing the post.

RedditPostUI

Write your post in Markdown. Any paragraphs you write will appear as normal body text in the final post. To create a code block, put three backticks on the line above the code listing and three more on the line below the listing.

```
// Put your code listing here
override func viewDidLoad() {
    super.viewDidLoad()
    // Do view setup here.
}
```

Then we you click the Post button, your code listing will appear in a block similar to the listing above, minus the backticks above and below the code.

By using Markdown code blocks for code listings in Reddit, your code will be much easier to read. People will be more likely to answer your question because you took the time to make an easy to read listing.


Where Did the Multiplatform SwiftUI Project Templates Go in Xcode 12.0?

October 1st, 2020

Filed under: Xcode | Be the first to comment!

As part of Xcode 12, Apple added project templates for creating SwiftUI apps that run on both iOS devices and Macs. In the Xcode 12 betas, these project templates appeared in the Multiplatform section.

Xcode12MultiplatformProjectTemplates

When Apple released iOS 14 in September, they also released Xcode 12.0. If you install Xcode 12.0 and create a project, you will see that the App and Document App projects are missing from the Multiplatform section. What happened?

The App and Document App templates require the macOS 11 SDK. Because macOS 11 was still in beta when Xcode 12.0 shipped, Apple did not include the macOS 11 SDK in Xcode 12.0. That’s why the App and Document App templates are missing in Xcode 12.0. No macOS 11 SDK, no App and Document App templates.

If you want to use the App and Document App templates, you must install Xcode 12.2, which includes the macOS 11 SDK. Apple will release Xcode 12.2 when macOS 11 ships. If you can’t wait for macOS 11 to ship, download the Xcode 12.2 beta.

UPDATE: November 2020

Xcode 12.2 is now available at the Mac App Store, and it includes the multiplatform SwiftUI project templates.


Adding a Swift Package to Multiple Targets

August 11th, 2020

Filed under: Xcode | Be the first to comment!

If your Xcode project has multiple targets and you add a Swift package, Xcode will let you add the package to only one of the targets. How do you add the package to the other targets?

Select a target from the project editor. Click the Add button in the Frameworks, Libraries, and Embedded Content section.

FrameworksAndLibraries

A sheet will open with a list of frameworks and libraries that you can add. The Swift package will appear in the list.


Disk Space Required to Install Xcode

April 29th, 2020

Filed under: Xcode | Be the first to comment!

People constantly post on Apple’s developer forums complaining that when they try to install Xcode, an alert opens saying they don’t have enough disk space to install it. These people always say they have enough space because they have more free space on their disk than the Xcode download. Usually the person asking the question has 15–20 GB of free space on their startup disk.

You Need More Free Space Than the Download Size

The Xcode file that you download is a compressed file. You need enough disk space to store both the compressed file you downloaded and the expanded file. Suppose your Xcode download is 8 GB. The expanded file is going to be bigger than that. Xcode 11.4.1 takes up 17.39 GB on my Mac. At this point you need 25.39 GB of free space. Add in some temporary storage space for swapping files, and you need a minimum of 30 GB of disk space to install Xcode.

30 GB of disk space is just an example. That may not be enough free space, especially for newer Xcode versions. Xcode releases keep getting larger over time so the amount of free disk space you need will increase as well.

Summary

If an alert opens saying you don’t have enough space to install Xcode, you don’t. Have enough free disk space that is at least 5 times the size of the compressed Xcode file you are going to download from Apple. I know that can be hard to do, especially if you are using a laptop with a 128 GB SSD, but you have to free up the space.

The app DevCleaner for Xcode can free up gigabytes of disk space by removing caches and other old files that accumulate over time.


Xcode 11: Export Mac App Archive

January 23rd, 2020

Filed under: Xcode | Be the first to comment!

Xcode 11 provides a subtle button to export a Mac app archive. In the Organizer, select an archive and scroll so you can see the Status column for the archive. Move the cursor over the Status column to make the Export App button appear.

Xcode11ExportApp