Will removing a debian package remove the data?

Solution 1:

Neither purge or remove will delete the mysql datadir.. see example

root@mail:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database so;
Query OK, 1 row affected (0.00 sec)

mysql> use so;
Database changed
mysql> CREATE TABLE example_autoincrement (
    ->          id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->          data VARCHAR(100)
    ->        );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO example_autoincrement (data) VALUES ('Hello world');
Query OK, 1 row affected (0.00 sec)

mysql> Bye
root@mail:~# apt-get remove mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libnet-daemon-perl libdbi-perl libhtml-template-perl mysql-server-core-5.1 mysql-client-core-5.1 libdbd-mysql-perl libplrpc-perl mysql-server-5.1 mysql-client-5.1
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  mysql-server
0 upgraded, 0 newly installed, 1 to remove and 49 not upgraded.
After this operation, 131kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 52161 files and directories currently installed.)
Removing mysql-server ...
root@mail:~# ls /var/lib/mysql/
debian-5.1.flag  ibdata1  ib_logfile0  ib_logfile1  mail.pid  mysql  mysql_upgrade_info  so
root@mail:~# apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  mysql-server
0 upgraded, 1 newly installed, 0 to remove and 49 not upgraded.
Need to get 94.8kB of archives.
After this operation, 131kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ lucid-updates/main mysql-server 5.1.41-3ubuntu12.10 [94.8kB]
Fetched 94.8kB in 0s (98.4kB/s)       
Selecting previously deselected package mysql-server.
(Reading database ... 52158 files and directories currently installed.)
Unpacking mysql-server (from .../mysql-server_5.1.41-3ubuntu12.10_all.deb) ...
Setting up mysql-server (5.1.41-3ubuntu12.10) ...
root@mail:~# /etc/init.d^C
root@mail:~# service mysql start
start: Job is already running: mysql
root@mail:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| so                 |
+--------------------+
3 rows in set (0.00 sec)

mysql> Bye
root@mail:~# apt-get purge mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libnet-daemon-perl libdbi-perl libhtml-template-perl mysql-server-core-5.1 mysql-client-core-5.1 libdbd-mysql-perl libplrpc-perl mysql-server-5.1 mysql-client-5.1
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  mysql-server*
0 upgraded, 0 newly installed, 1 to remove and 49 not upgraded.
After this operation, 131kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 52161 files and directories currently installed.)
Removing mysql-server ...
root@mail:~# 
root@mail:~# 
root@mail:~# ls /var/lib/mysql/
debian-5.1.flag  ibdata1  ib_logfile0  ib_logfile1  mail.pid  mysql  mysql_upgrade_info  so
root@mail:~# 

Solution 2:

I think the "data" it is referring to is any nonexecutable resources shipped in the package, e.g. things found in /usr/share. Are you specifically concerned about mysql, or another package?

If data is valuable to you you should be backing it up anyway.

Solution 3:

As I want to package one for ElasticSearch I need to know what is expected.

If I understand you correctly, you are in the process of packaging ElasticSearch as .deb for distribution.

If that is the case, and you are building a .deb package for public distribution I recommend you 1) fully read the relevant sections on packaging in the Debian Developer's Reference and ask on the appropriate Debian mailing-list (probably Debian-Developer).

Generally speaking, remove will just remove the binaries and libraries associated with a package while purge will remove the binaries, libraries, documentation, and configuration files. It is considered bad form for your package to nuke the user's data without at least informing them first.

I really suggest you check with an experienced Debian Maintainer before deciding how to proceed - especially if you want to submit this package to Debian repositories.

Another word of device: As a long-time Debian user, almost nothing annoys me more than a 3rd party distributing their software as a .deb that does follow standard Debian conventions. If you want to keep your users, please ensure that your package is well maintained and meets the guidelines as laid out by the Debian team.