Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Amazon Redshift Cookbook

You're reading from   Amazon Redshift Cookbook Recipes for building modern data warehousing solutions

Arrow left icon
Product type Paperback
Published in Apr 2025
Publisher Packt
ISBN-13 9781836206910
Length 468 pages
Edition 2nd Edition
Arrow right icon
Authors (3):
Arrow left icon
Shruti Worlikar Shruti Worlikar
Author Profile Icon Shruti Worlikar
Shruti Worlikar
 Patel Patel
Author Profile Icon Patel
Patel
Anusha Challa Anusha Challa
Author Profile Icon Anusha Challa
Anusha Challa
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Getting Started with Amazon Redshift FREE CHAPTER 2. Data Management 3. Loading and Unloading Data 4. Zero-ETL Ingestions 5. Scalable Data Orchestration for Automation 6. Platform Authorization and Security 7. Data Authorization and Security 8. Performance Optimization 9. Cost Optimization 10. Lakehouse Architecture 11. Data Sharing with Amazon Redshift 12. Generative AI and ML with Amazon Redshift 13. Other Books You May Enjoy
14. Index
Appendix

Connecting to Amazon Redshift using Command Line (psql)

PSQL is a command line front-end to PostgreSQL. It enables you to query the data in an Amazon Redshift data warehouse (serverless or provisioned cluster) interactively. In this recipe, we will see how to install psql and run interactive queries.

Getting ready

To complete this recipe, you will need:

  • Install psql (comes with PostgreSQL). To learn more about using psql, you can refer to https://www.postgresql.org/docs/8.4/static/app-psql.html. Based on your operating system, you can download the corresponding PostgreSQL binary from https://www.postgresql.org/download/.
  • If you are using Windows, set the PGCLIENTENCODING environment variable to UTF-8 using the following command using the Windows command-line interface:
    set PGCLIENTENCODING=UTF8
    
  • Capture the Amazon Redshift login credentials.
  • Modify the security group attached to the Amazon Redshift cluster to allow connection from the server or client running the psql application, which will allow access to execute the psql code.

How to do it…

The following steps will let you connect to Amazon Redshift through a command-line interface:

  1. Open the command-line interface and type psql to make sure it is installed.
  2. Provide the connection credentials as shown in the following command line to connect to Amazon Redshift:
    C:\Program Files\PostgreSQL\10\bin> .\psql -h cookbookcluster-2ee55abd.cvqfeilxsadl.eu-west-1.redshift.amazonaws.com -d dev -p 5439 -U dbuser
    Password for user dbuser:
    Type "help" for help.
    dev=# help
    You are using psql, the command-line interface to PostgreSQL.
    Type:  \copyright for distribution terms
            \h for help with SQL commands
            \? for help with psql commands
           \g or terminate with semicolon to execute query
           \q to quit
    

To connect to Amazon Redshift using the psql command line, you will need the clusters endpoint, the database username, and the port. You can use the following command to connect to the Redshift data warehouse:

psql -h <clusterendpoint> -U <dbuser> -d <databasename> -p <port>
  1. To check the database connection, you can use a sample query as specified in the following command:
    dev=# select sysdate;
    

You are now successfully connected to the Amazon Redshift data warehouse and ready to run the SQL queries!

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Amazon Redshift Cookbook
You have been reading a chapter from
Amazon Redshift Cookbook - Second Edition
Published in: Apr 2025
Publisher: Packt
ISBN-13: 9781836206910
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon