Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Customize the PostgreSQL Prompt With psqlrc

A complete guide to customizing PostgreSQL's psql prompt with psqlrc: file locations, PROMPT1/2/3, substitution codes, multiline alignment, COPY prompts, ANSI colors, version-specific files, and troubleshooting.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Edit your personal psqlrc startup file, define PROMPT1, PROMPT2, and PROMPT3 with psql’s set command, then start a new psql session. On Unix-like systems the usual file is ~/.psqlrc; on Windows it is %APPDATA%postgresqlpsqlrc.conf. A compact starting point is:

set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

This displays the connected user, database, input state, and privilege-sensitive prompt character while keeping continuation and COPY FROM STDIN prompts distinct.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What psqlrc changes and when psql reads it

psql reads startup configuration before it accepts your normal commands. PostgreSQL’s documentation describes the prompts as customizable to your preference. The personal file is read after connection and before regular commands, so a prompt definition there applies automatically to each new session unless you explicitly override startup processing.

The file is plain text. It does not change the server, database schema, authentication, or SQL history; it changes the behavior of the psql client that reads it. You can therefore keep different prompt designs on different computers or for different client versions without altering a shared PostgreSQL installation.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Unix-like systems

Create or edit ~/.psqlrc in the home directory of the operating-system account that launches psql. A shell editor, graphical text editor, or terminal editor is sufficient. The leading dot makes the file hidden in many directory listings, but it is still an ordinary text file.

Windows

Use %APPDATA%postgresqlpsqlrc.conf. The filename is psqlrc.conf, rather than the Unix-style dotfile. If you want the configuration in another location, set the PSQLRC environment variable to that path before launching psql.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

System-wide, personal, and version-specific files

psql can read a system-wide psqlrc and the user’s personal file. The personal startup file is processed after the connection is established, so personal definitions can provide the settings you want for interactive work. Supplying -X when starting psql disables startup-file processing, which is useful for recovery and for scripts that must not inherit interactive preferences.

You can isolate settings by client version with names such as ~/.psqlrc-16 or ~/.psqlrc-16.15. This prevents assumptions about escape sequences, defaults, or other client behavior from one PostgreSQL release from silently affecting another.

The three prompt variables

Each variable controls a different psql state. Defining only PROMPT1 leaves the other states at their existing values, so a complete customization normally sets all three.

Variable When it appears What to optimize
PROMPT1 Normal interactive input Identity and context you want to see before each command
PROMPT2 While a SQL statement or other input is incomplete A clear continuation marker and a useful explanation of the waiting state
PROMPT3 While entering rows for COPY FROM STDIN A visually unmistakable data-entry prompt

Use psql’s set command, followed by the variable name and a quoted prompt string. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

Prompt substitutions you can use

Prompt strings are expanded when psql displays them. The following documented substitutions cover the common identity, connection, state, and alignment needs.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
Substitution Displayed value Typical reason to use it
%n Connected database user Distinguish roles when several accounts are used
%/ Database name Prevent running a command in the wrong database
%R Input-state indicator Show whether psql is waiting for more input or in another special state
%# Privilege-sensitive prompt character Keep psql’s distinction between privileged and non-privileged connections visible
%w Whitespace matching the width of the latest PROMPT1 Align a multiline continuation prompt underneath the normal prompt
%M Full host name Separate local, staging, and remote servers
%m Truncated host name Show a shorter host label when the full name is too wide
%p Port Distinguish clusters that share a host
%x Transaction status Make transaction context visible during interactive work
%l Statement line number Track the line number within an input statement
%:name: Value of a psql variable named name Insert context stored in a psql variable
%% A literal percent sign Print percent characters without starting a substitution
Backtick command substitution Output from a command substitution Add dynamically generated context, only when the extra complexity is worthwhile

Keep the first version short. Every additional field consumes horizontal space, and command substitution can make a prompt slower or harder to diagnose. Add host, port, transaction, or version context only when it answers a real question while you work.

Build a reliable baseline prompt

The baseline below is a practical starting point because it exposes identity, database, input state, and privilege while handling continuation input separately.

  1. Open the appropriate file: ~/.psqlrc on Unix-like systems or %APPDATA%postgresqlpsqlrc.conf on Windows.
  2. Enter the three definitions exactly as shown:
set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '
  1. Save the file as plain text. Ensure a Windows editor has not added an extra filename extension such as .txt.
  2. Exit the current psql session and start psql again. Startup files are read when the new client session starts; an already-running session will not automatically reread a file you just changed.
  3. Check the first prompt. It should contain the database user, an @ separator, the database name, an input-state marker, and the privilege-sensitive prompt character.

The trailing spaces in the definitions are intentional. They separate the prompt from the command you type and make the line easier to scan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right information density

There is no universally best prompt. The right design depends on how often you switch users, databases, hosts, and transaction contexts.

Design Example Information density Best fit
Identity only set PROMPT1 '%n@%/ %# ' Low Local work where host and port are already obvious
Baseline state-aware set PROMPT1 '%n@%/%R%# ' Medium Most interactive sessions
Remote-aware set PROMPT1 '%n@%M:%p/%R%# ' High Several hosts or clusters with overlapping database names
Transaction-aware set PROMPT1 '%n@%/%x%R%# ' High Work in which transaction state must remain visible
Multiline-aligned set PROMPT2 '%w%R%# ' Focused on readability Long statements and deliberate continuation editing

These examples are alternatives, not lines that should all be concatenated. A prompt that includes full host, port, transaction state, and several other markers can become wider than the command itself. Start with the baseline and add one field at a time.

Make incomplete input obvious with PROMPT2

PROMPT2 is more than a second prompt character. Its %R expansion can indicate why psql is waiting: an unterminated command, block comment, quoted string or identifier, dollar-quoted string, or unmatched parenthesis. This is useful when a statement appears to have stopped responding but is actually waiting for the rest of your input.

The recommended definition uses %w before %R. psql supplies whitespace matching the width of the latest PROMPT1, so the continuation marker starts in a consistent column instead of drifting under different user or host names.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '

If the continuation line shows a state marker you did not expect, inspect the command for an open quote, comment, dollar-quoted section, parenthesis, or other unfinished construct. You can cancel the unfinished input with the normal psql cancellation method for your terminal, then correct the statement and try again.

Give COPY input its own prompt

During COPY FROM STDIN, psql uses PROMPT3. Set it to a marker that cannot be mistaken for an ordinary SQL prompt:

set PROMPT3 '>> '

In this state, %R produces no text, so placing the usual input-state substitution in PROMPT3 does not provide additional information. A fixed marker such as >> makes it clear that psql expects data rows rather than another SQL command.

Add host, port, and transaction context carefully

Host and port

Use %M for the full host name or %m for its truncated form. Add %p when more than one PostgreSQL cluster can be reached through the same host. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
set PROMPT1 '%n@%M:%p/%R%# '

This is especially helpful when database names are identical across environments. If host and port are stable and obvious from your terminal or connection workflow, omit them to preserve space.

Transaction status

%x inserts transaction status. Put it near the identity and database fields when knowing the current transaction context matters more than a narrow prompt:

set PROMPT1 '%n@%/%x%R%# '

Because transaction information changes as you work, it can be more valuable than a permanent host label for sessions focused on transaction control.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Line numbers and psql variables

%l adds the statement line number. A reference such as %:name: inserts the value of a psql variable named name. These are specialized additions: include them when you actively use multiline statements or set session variables that deserve constant visibility.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Command substitution

Backtick command substitution can add dynamically generated information, but it also adds another moving part to startup configuration. Use it only when the output is short, predictable, and genuinely useful. Test it separately before placing it in a prompt that runs every time psql redraws the line.

Add ANSI colors without breaking Readline alignment

Terminal color control bytes are not visible characters, but Readline still needs to know that they occupy no screen columns. Wrap non-printing control bytes in %[ and %]. PostgreSQL’s documented example is:

set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

This requests bold yellow text on a black background on terminals that support those ANSI attributes, then resets the color before the privilege-sensitive prompt character. The visible prompt remains the same identity-and-state design as the uncolored version.

Why the wrappers matter

Without the non-printing delimiters, Readline may count escape sequences as visible width. Cursor movement, editing, and wrapping can then occur at the wrong columns even though the prompt looks correct at first glance. The wrappers tell psql and Readline which bytes change terminal presentation but do not consume screen space.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Color testing checklist

  • Confirm that the terminal actually supports the requested ANSI sequence.
  • Type a command long enough to reach the edge of the terminal and verify that editing and wrapping remain aligned.
  • Check a continuation line, not only PROMPT1, because a colored normal prompt can still leave an unaligned PROMPT2.
  • Keep the reset sequence in the prompt so subsequent command text does not inherit the prompt color.

If alignment becomes unreliable, remove color first and verify the plain prompt. Reintroduce the ANSI sequence only after the uncolored definitions work.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use version-specific files when clients differ

A single personal file is convenient when all of your psql clients behave alike. Version-specific files such as ~/.psqlrc-16 and ~/.psqlrc-16.15 provide a safer boundary when you maintain multiple client releases. They let you keep assumptions about escape sequences or defaults next to the version that needs them instead of applying one design indiscriminately.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Keep the shared portion deliberately conservative, then place version-sensitive definitions in the matching file. When diagnosing a change after an upgrade, compare the version-specific file with the general file before changing the server or shell environment.

Troubleshoot a startup customization

Start with psql -X

If psql reports an error during startup or opens with a broken prompt, launch it with -X. This bypasses psqlrc processing for that session, giving you a clean client in which to inspect or repair the file. Once the file is corrected, start psql normally to verify that the startup configuration loads.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reduce the file to a known-good baseline

  1. Use psql -X to confirm that the server connection itself works.
  2. Temporarily leave only the three baseline set lines in the startup file.
  3. Start a new normal session and verify PROMPT1, PROMPT2, and PROMPT3 independently.
  4. Add one substitution or color sequence at a time, restarting psql after each change.
  5. When the problem returns, the last addition identifies the setting to correct or remove.

The file appears to be ignored

  • Confirm the path and filename for your operating system.
  • Check that the file is readable by the account running psql.
  • Make sure the PSQLRC environment variable is not pointing somewhere else.
  • Verify that you did not start the client with -X.
  • Exit and relaunch psql after editing; an existing session will not automatically reread the file.

The prompt is too wide or hard to scan

Remove fields in reverse order of importance. Full host names, ports, transaction status, line numbers, and command substitutions are all optional. Keep the user and database when identity is the main risk; add host or port only when those values prevent an actual mistake.

Continuation alignment is wrong

Use %w at the beginning of PROMPT2 and make sure the width-changing parts of PROMPT1 are handled consistently. If color is enabled, verify that every non-printing control sequence is enclosed by %[ and %]. Test again with a long input line that wraps at the terminal edge.

Colors or escape sequences cause errors

Return to the plain baseline, then add the documented color example exactly. Keep the reset sequence and test in a terminal known to support ANSI colors. If the client versions differ, move the color definition into an appropriate version-specific startup file.

A practical validation routine

After changing psqlrc, validate each state instead of judging only the first line you see.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Connect as a known user and verify that %n and %/ identify the expected role and database.
  2. Check the prompt character supplied by %# and confirm that it changes as expected for the privilege context of the connection.
  3. Begin an intentionally incomplete statement and inspect PROMPT2. Confirm that the continuation marker is aligned and that %R communicates the waiting state.
  4. Enter a COPY FROM STDIN operation and verify that PROMPT3 is unmistakable. End the data-entry mode using the normal psql procedure for your platform.
  5. If host, port, transaction, line-number, or variable substitutions are enabled, compare each displayed value with the connection and statement you deliberately created for the test.
  6. Repeat the checks in any other psql client version that uses the same computer, or place differing definitions in version-specific files.

Configuration choices at a glance

Goal Recommended setting Trade-off
Identify role and database quickly %n@%/ Does not identify a remote host by itself
Diagnose unfinished input %R in both normal and continuation prompts Adds a state marker to every normal prompt
Keep multiline input aligned %w at the start of PROMPT2 Continuation spacing follows the current PROMPT1 width
Distinguish servers %M, %m, and optionally %p Longer prompts and more visual noise
Expose transaction context %x Useful status information consumes a prompt position
Improve visual scanning ANSI color wrapped with %[ and %] Depends on terminal support and correct non-printing-width markers
Recover from a bad configuration psql -X All startup customizations are skipped for that session

Recommended final configuration

For most interactive users, begin with this readable, portable configuration and expand only when a missing piece of context has caused a real problem:

set PROMPT1 '%n@%/%R%# '
set PROMPT2 '%w%R%# '
set PROMPT3 '>> '

Add %M:%p when hosts or ports are easy to confuse, add %x when transaction state is central to your work, and add the documented ANSI wrapper only after plain-text editing and wrapping behave correctly. Keep psql -X available as the escape hatch whenever a startup edit prevents a normal session.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.