Run:
arturo@ubuntuvm01:~$ docker exec -ti <container name> bash
Example:

Docker is a powerful platform for developing, shipping, and running applications inside containers. Here are some of the main Docker commands that you’ll frequently use:
1. Docker Version:
docker --version
2. Docker Help:
docker --help
3. Docker Images:
docker images
4. Docker Pull:
docker pull image_name:tag
5. Docker Run:
docker run [options] image_name [command]
6. Docker PS:
docker ps
7. Docker PS (All Containers):
docker ps -a
8. Docker Stop:
docker stop container_id_or_name
9. Docker Kill:
docker kill container_id_or_name
10. Docker Start:
docker start container_id_or_name
11. Docker Remove:
docker rm container_id_or_name
12. Docker Logs:
docker logs container_id_or_name
13. Docker Exec:
docker exec [options] container_id_or_name command
14. Docker Network:
docker network ls
15. Docker Volume:
docker volume ls
16. Docker Build:
docker build -t image_name:tag path_to_Dockerfile_directory
17. Docker Compose:
docker-compose [options] command
18. Docker Save and Load:
docker save -o image_name.tar image_name:tag docker load -i image_name.tar
19. Docker Push:
docker push image_name:tag
20. Docker Search:
docker search search_term
These are some of the essential Docker commands to get you started. Docker provides many more commands and options for more advanced use cases and customization. You can always refer to the official Docker documentation or use the docker --help command to explore more options and details for each command.
To copy your SSH key to a remote host, you can use the ssh-copy-id command, which is a convenient way to install your public key on a remote server. Here are the steps to do this:
ssh-keygen command. Open a terminal on your local machine and run: ssh-keygen -t rsa -b 4096 -C "your_email@example.com" Replace "your_email@example.com" with your actual email address. This command will generate a new SSH key pair and store it in the default location (~/.ssh/id_rsa for the private key and ~/.ssh/id_rsa.pub for the public key).ssh-copy-id command to copy your public key to the remote host. Replace your_username and remote_host with the appropriate values:bashCopy codessh-copy-id your_username@remote_host You’ll be prompted to enter your password on the remote host for authentication.Note: If you’re using a custom SSH port, you can specify it with the -p option, like this: ssh-copy-id -p custom_port your_username@remote_hostssh your_username@remote_host You should be logged in without being prompted for a password.By following these steps, you’ve securely copied your SSH key to the remote host, allowing you to log in without needing to enter a password each time. This is a more secure and convenient way to access remote servers.
To display block I/O metrics (input/output) on a PostgreSQL server, you can use various methods and tools. Here are some options:
pg_stat_statements extension can provide insight into the number of blocks read and written by specific queries. To use it, you need to enable the extension and monitor the pg_stat_statements view.postgresql.conf file and then restarting PostgreSQL:shared_preload_libraries = 'pg_stat_statements' After that, you can query the pg_stat_statements view to see I/O statistics for specific queries:SELECT query, total_time, rows, shared_blks_read, shared_blks_hit, local_blks_read, local_blks_hit, temp_blks_read, temp_blks_written FROM pg_stat_statements; This query will display I/O metrics for the recorded statements.pg_stat_activity view to monitor ongoing queries and check their I/O activity. This view includes information about the current query being executed, such as the number of blocks read and written.SELECT pid, query, pg_size_pretty(pg_stat_get_blocks_fetched(pid)) AS blocks_fetched, pg_size_pretty(pg_stat_get_blocks_hit(pid)) AS blocks_hit FROM pg_stat_activity; This query shows the process ID (pid), the query being executed (query), the number of blocks fetched, and the number of blocks hit in the shared buffer cache.pg_stat_bgwriter view provides statistics about the background writer process, which manages PostgreSQL’s background I/O operations. It includes information about buffers written and other I/O-related metrics.SELECT checkpoints_timed, buffers_heckpoint, buffers_clean, buffers_backend, buffers_alloc FROM pg_stat_bgwriter; This query will show various I/O-related metrics related to background writing.iostat on Linux and Task Manager on Windows. These tools can provide system-wide I/O metrics, including disk reads and writes by the PostgreSQL process.iostat -xk 1 | grep postgres This command will display real-time I/O metrics for the PostgreSQL process.Remember that monitoring I/O metrics can help identify performance bottlenecks and optimize your PostgreSQL database for better performance. Consider using a combination of these methods to gain a comprehensive understanding of your system’s I/O activity.
You can display the active sessions (connections) on a PostgreSQL server by querying the pg_stat_activity view. This view provides information about the currently active connections and their associated queries. Here’s how you can use it:
psql command-line client or another PostgreSQL client of your choice. You may need to provide the appropriate username and password or other authentication details.bashCopy codepsql -U your_username -d your_database_namepg_stat_activity: Once connected, you can query the pg_stat_activity view to see the active sessions. You can run the following SQL query: SELECT * FROM pg_stat_activity; This query will return a list of all active sessions, including information such as the process ID (pid), username (usename), database (datname), client address (client_addr), and the SQL query being executed (query). The state column provides the current state of each session, which can be helpful for diagnosing issues.SELECT usename, datname, query FROM pg_stat_activity; You can also use WHERE clauses to filter the results based on specific criteria. For instance, to see only sessions with a specific application name, you can do: SELECT * FROM pg_stat_activity WHERE application_name = 'your_application_name';psql: After viewing the active sessions, you can exit the PostgreSQL client by typing: \qThis will return you to the command line.
Keep in mind that pg_stat_activity provides a snapshot of active sessions at the time you run the query. If you want to continuously monitor sessions in real-time, you may want to use monitoring tools or automate queries to periodically check the pg_stat_activity view.
Monitoring the performance of a PostgreSQL server is crucial to ensure that it’s running efficiently and to identify potential issues before they become critical. Here are steps and tools you can use to monitor the performance of a PostgreSQL server:
1. PostgreSQL Logs:
/var/log/postgresql/ on Linux.2. PostgreSQL’s Built-in Monitoring:
pg_stat_activity, pg_stat_statements, and pg_stat_bgwriter. You can query these views to gather information about active connections, query statistics, and the state of background processes.SELECT * FROM pg_stat_activity;3. pg_stat_statements:
pg_stat_statements extension, consider doing so. This extension tracks query execution statistics, which can be invaluable for identifying slow or resource-intensive queries.postgresql.conf) and restart PostgreSQL.pg_stat_statements to analyze query performance.4. Performance Monitoring Tools:
pg_prometheus extension to export metrics to Prometheus.5. PostgreSQL Configuration Tuning:
postgresql.conf) based on your server’s hardware and workload. Key parameters to consider include shared_buffers, work_mem, and max_connections. Tweaking these settings can have a significant impact on performance.6. Resource Usage:
top, htop, or dedicated server monitoring solutions. High resource utilization can indicate performance bottlenecks.7. Slow Query Log:
log_statement = 'all' and log_duration = 0 in postgresql.conf) to log slow queries. This can help you identify and optimize problematic queries.8. Vacuum and Maintenance:
VACUUM and ANALYZE commands to optimize table and index performance. You can automate this process using tools like autovacuum.9. Database Indexing:
10. Query Optimization: – Use the EXPLAIN command to analyze query execution plans and identify opportunities for optimization. Make use of appropriate indexes, rewrite queries, and consider caching where applicable.
11. Set Up Alerts: – Configure monitoring alerts to be notified of critical issues promptly. This can help you proactively address performance problems.
12. Regular Maintenance: – Continuously monitor and fine-tune your PostgreSQL server to adapt to changing workloads and requirements.
Remember that PostgreSQL performance tuning is an ongoing process, and it may require periodic review and adjustments as your workload evolves. Monitoring and optimizing your PostgreSQL server is essential to ensure that it performs optimally and meets the needs of your applications.
1. Backup your existing database: Before performing any upgrades, it’s essential to create a backup of your existing PostgreSQL database to prevent data loss in case something goes wrong. You can use the pg_dump utility to create a backup of your database.
pg_dump -U your_username -d your_database_name -f backup_file.sql
2. Check system requirements: Ensure that your system meets the hardware and software requirements for the new version of PostgreSQL you plan to install. You can find this information in the PostgreSQL documentation.
3. Review release notes: Carefully read the release notes for the version you want to upgrade to. This will provide information about changes, potential incompatibilities, and any specific upgrade instructions.
4. Install the new PostgreSQL version:
apt, while on CentOS, you can use yum.5. Stop the old PostgreSQL server: Before you can perform the upgrade, you must stop the old PostgreSQL server. You can use the following command:
sudo systemctl stop postgresql
6. Upgrade the PostgreSQL data directory:
pg_upgrade utility to upgrade your data directory. This tool is provided by PostgreSQL and is designed to facilitate the upgrade process.pg_upgrade:pg_upgrade -b /path/to/old/bin -B /path/to/new/bin -d /path/to/old/data -D /path/to/new/data
Replace /path/to/old/bin, /path/to/new/bin, /path/to/old/data, and /path/to/new/data with the actual paths to your old and new PostgreSQL binaries and data directories.
7. Verify the upgrade: After running pg_upgrade, you should test your upgraded PostgreSQL database to ensure it functions correctly. Connect to the new database using the PostgreSQL client (psql) and perform some basic queries to confirm that everything is working as expected.
8. Update your applications: If you have any applications or scripts that interact with your PostgreSQL database, make sure they are compatible with the new version. You might need to update database drivers or modify queries if there are any breaking changes.
9. Start the new PostgreSQL server: Once you are confident that the upgrade was successful and your applications are working correctly with the new version, you can start the new PostgreSQL server:
sudo systemctl start postgresql
10. Monitor and optimize: After the upgrade, monitor the performance of your PostgreSQL server and make any necessary optimizations. This may include adjusting configuration settings, indexing, and query optimization.
Remember that upgrading a production database is a critical task, so always perform it with caution and consider testing the process in a development or staging environment before upgrading your production database.